提交 cc0ce00b authored 作者: JarvanMo's avatar JarvanMo

update readme

上级 c0bc73b2
...@@ -10,11 +10,46 @@ ...@@ -10,11 +10,46 @@
## 引入 ## 引入
## 初始化 ## 初始化
```dart ```dart
Fluwx.registerApp("yourAppId"); Fluwx.registerApp(RegisterModel(appId: "your app id", doOnAndroid: true, doOnIOS: true));
``` ```
或者 - appId:在微信平台申请的appId
```dart - doOnAndroid:是否在android平台上执行此操作。
Fluwx.registerApp(); - doOnIOS:是否在平台上执行此操作。
每一个字段都是非必须的,但是如果不传appId或```doOnAndroid: false```或者```doOnIOS: false```,请务必在对应平台手动注册```WXApi```,以保证
Fluwx正常工作。
注册完成后,请在对应平台添加如下代码:
Android
```kotlin
FluwxShareHandler.setWXApi(wxapi)
``` ```
iOS
For help on editing plugin code, view the [documentation](https://flutter.io/platform-plugins/#edit-code). ```oc
\ No newline at end of file isWeChatRegistered = YES;
```
你也可以取消注册你的app
```dart
Fluwx.unregisterApp(RegisterModel(doOnAndroid: true, doOnIOS: true));
```
##开始分享
```dart
var fluwx = Fluwx();
fluwx.share(WeChatShareImageModel(image: "imagePath",thumbnail: "thumbanailPath"));
fluwx.share(
WeChatShareWebPageModel(
webPage: "https://github.com/JarvanMo/fluwx",
title: "MyGithub",
thumbnail: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534532387799&di=12701cc3f20c1a78a5c7524ec33b4c59&imgtype=0&src=http%3A%2F%2Fwww.cssxt.com%2Fuploadfile%2F2017%2F1208%2F20171208110834538.jpg',
)).then((result){
},onError: (msg){
});
```
```fluwx.share(WeChatShareModel)```目前仅支持系统内```WeChatShareModel```的子类,不支持自定义。
所有字段名字和官方文档基本是一致的。
##图片处理
目前所有需要图片的地方支持网络图片及assets图片。
使用assets图片需要添加```assets://```。
也可以在assets图片添加```?package=package_name````以读取指定包的图片。
未来可能支持```file://```
如果不指定schema或者schema错误,将会被处理为网络图片,请谨慎。
##注意
所有涉及缩略的最好给Fluwx一个合格的图片(小于32k),否则Fluwx将会对图片进行处理,这样做的结果可能并不是你所预期的,如缩略图被裁剪。
package com.jarvan.fluwx package com.jarvan.fluwx
import com.jarvan.fluwx.constant.CallResult
import com.jarvan.fluwx.constant.WeChatPluginMethods import com.jarvan.fluwx.constant.WeChatPluginMethods
import com.jarvan.fluwx.handler.WeChatPluginHandler import com.jarvan.fluwx.handler.FluwxShareHandler
import com.tencent.mm.opensdk.openapi.WXAPIFactory
import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.MethodCallHandler
...@@ -15,28 +13,28 @@ class FluwxPlugin(private var registrar: Registrar) : MethodCallHandler { ...@@ -15,28 +13,28 @@ class FluwxPlugin(private var registrar: Registrar) : MethodCallHandler {
@JvmStatic @JvmStatic
fun registerWith(registrar: Registrar): Unit { fun registerWith(registrar: Registrar): Unit {
val channel = MethodChannel(registrar.messenger(), "fluwx") val channel = MethodChannel(registrar.messenger(), "fluwx")
WeChatPluginHandler.setRegistrar(registrar) FluwxShareHandler.setRegistrar(registrar)
WeChatPluginHandler.setMethodChannel(channel) FluwxShareHandler.setMethodChannel(channel)
channel.setMethodCallHandler(FluwxPlugin(registrar)) channel.setMethodCallHandler(FluwxPlugin(registrar))
} }
} }
override fun onMethodCall(call: MethodCall, result: Result): Unit { override fun onMethodCall(call: MethodCall, result: Result): Unit {
if(call.method == WeChatPluginMethods.REGISTER_APP ){ if(call.method == WeChatPluginMethods.REGISTER_APP ){
WeChatPluginHandler.registerApp(call,result) FluwxShareHandler.registerApp(call,result)
return return
} }
if(call.method == WeChatPluginMethods.UNREGISTER_APP){ if(call.method == WeChatPluginMethods.UNREGISTER_APP){
WeChatPluginHandler.unregisterApp(call) FluwxShareHandler.unregisterApp(call)
result.success(true) result.success(true)
return return
} }
if( call.method.startsWith("share")){ if( call.method.startsWith("share")){
WeChatPluginHandler.handle(call, result) FluwxShareHandler.handle(call, result)
}else{ }else{
result.notImplemented() result.notImplemented()
} }
......
package com.jarvan.fluwx.handler package com.jarvan.fluwx.handler
import android.util.Log
import com.jarvan.fluwx.constant.CallResult import com.jarvan.fluwx.constant.CallResult
import com.jarvan.fluwx.constant.WeChatPluginMethods import com.jarvan.fluwx.constant.WeChatPluginMethods
import com.jarvan.fluwx.constant.WechatPluginKeys import com.jarvan.fluwx.constant.WechatPluginKeys
...@@ -25,7 +24,7 @@ import kotlinx.coroutines.experimental.launch ...@@ -25,7 +24,7 @@ import kotlinx.coroutines.experimental.launch
* 冷风如刀,以大地为砧板,视众生为鱼肉。 * 冷风如刀,以大地为砧板,视众生为鱼肉。
* 万里飞雪,将穹苍作烘炉,熔万物为白银。 * 万里飞雪,将穹苍作烘炉,熔万物为白银。
**/ **/
object WeChatPluginHandler { object FluwxShareHandler {
private var wxApi: IWXAPI? = null private var wxApi: IWXAPI? = null
private var channel: MethodChannel? = null private var channel: MethodChannel? = null
...@@ -34,9 +33,12 @@ object WeChatPluginHandler { ...@@ -34,9 +33,12 @@ object WeChatPluginHandler {
fun setMethodChannel(channel: MethodChannel) { fun setMethodChannel(channel: MethodChannel) {
WeChatPluginHandler.channel = channel FluwxShareHandler.channel = channel
} }
fun setWXApi(wxApi:IWXAPI){
this.wxApi = wxApi
}
fun registerApp(call: MethodCall, result: MethodChannel.Result) { fun registerApp(call: MethodCall, result: MethodChannel.Result) {
...@@ -76,7 +78,7 @@ object WeChatPluginHandler { ...@@ -76,7 +78,7 @@ object WeChatPluginHandler {
} }
fun setRegistrar(registrar: PluginRegistry.Registrar) { fun setRegistrar(registrar: PluginRegistry.Registrar) {
WeChatPluginHandler.registrar = registrar FluwxShareHandler.registrar = registrar
} }
......
...@@ -5,7 +5,7 @@ import android.content.Intent; ...@@ -5,7 +5,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Button; import android.widget.Button;
import com.jarvan.fluwx.handler.WeChatPluginHandler; import com.jarvan.fluwx.handler.FluwxShareHandler;
import com.tencent.mm.opensdk.modelbase.BaseReq; import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp; import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler; import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
...@@ -35,7 +35,7 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler{ ...@@ -35,7 +35,7 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler{
@Override @Override
public void onResp(BaseResp resp) { public void onResp(BaseResp resp) {
WeChatPluginHandler.INSTANCE.onResp(resp); FluwxShareHandler.INSTANCE.onResp(resp);
} }
......
...@@ -15,11 +15,9 @@ class _MyAppState extends State<MyApp> { ...@@ -15,11 +15,9 @@ class _MyAppState extends State<MyApp> {
void initState() { void initState() {
super.initState(); super.initState();
// initPlatformState(); // initPlatformState();
Fluwx.registerApp(RegisterModel(appId: "wxd930ea5d5a258f4f")).then((result) { Fluwx.registerApp(RegisterModel(
print("succes-->$result"); appId: "wxd930ea5d5a258f4f", doOnAndroid: true, doOnIOS: true));
}, onError: (value) {
print("--->$value");
});
} }
// Platform messages are asynchronous, so we initialize in an async method. // Platform messages are asynchronous, so we initialize in an async method.
...@@ -50,8 +48,8 @@ class _MyAppState extends State<MyApp> { ...@@ -50,8 +48,8 @@ class _MyAppState extends State<MyApp> {
// thumbnail: 'http://b.hiphotos.baidu.com/image/h%3D300/sign=4bfc640817d5ad6eb5f962eab1c939a3/8718367adab44aedb794e128bf1c8701a08bfb20.jpg', // thumbnail: 'http://b.hiphotos.baidu.com/image/h%3D300/sign=4bfc640817d5ad6eb5f962eab1c939a3/8718367adab44aedb794e128bf1c8701a08bfb20.jpg',
// fluwx.share( // fluwx.share(
// WeChatShareWebPageModel( // WeChatShareWebPageModel(
// webPage: "https://www.jianshu.com/", // webPage: "https://github.com/JarvanMo/fluwx",
// title: "简书", // title: "MyGithub",
// thumbnail: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534532387799&di=12701cc3f20c1a78a5c7524ec33b4c59&imgtype=0&src=http%3A%2F%2Fwww.cssxt.com%2Fuploadfile%2F2017%2F1208%2F20171208110834538.jpg', // thumbnail: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534532387799&di=12701cc3f20c1a78a5c7524ec33b4c59&imgtype=0&src=http%3A%2F%2Fwww.cssxt.com%2Fuploadfile%2F2017%2F1208%2F20171208110834538.jpg',
// ) // )
// ).then((result){ // ).then((result){
...@@ -59,6 +57,7 @@ class _MyAppState extends State<MyApp> { ...@@ -59,6 +57,7 @@ class _MyAppState extends State<MyApp> {
// },onError: (msg){ // },onError: (msg){
// print(msg); // print(msg);
// }); // });
// fluwx.share(WeChatShareImageModel(image: "imagePath",thumbnail: "thumbanailPath"));
}, },
child: new Text("share ")), child: new Text("share ")),
), ),
......
class RegisterModel { class RegisterModel {
final String appId; final String appId;
final bool doIOS; final bool doOnIOS;
final bool doAndroid; final bool doOnAndroid;
RegisterModel({ RegisterModel({
this.appId, this.appId,
this.doIOS: true, this.doOnIOS: true,
this.doAndroid: true}); this.doOnAndroid: true});
Map toMap(){ Map toMap(){
return { return {
"appId":appId, "appId":appId,
"iOS":doIOS, "iOS":doOnIOS,
"android":doAndroid "android":doOnAndroid
}; };
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论