友盟分享插件 for Flutter
在最近的实际项目中测试并使用了该库,目前当前库添加了常用的微博、qq、微信这个几个库 因为Umeng分享支持的第三方平台比较多,无法一一测试;如遇到问题请issue 或 PR;
集成到项目中有两种方法:
在包管理文件pubspec.yaml中添加如下:
dependencies:
flutter_umeng_ushare: ^1.0.3
git clone 项目到本地后, 在包管理文件pubspec.yaml中添加如下:
dependencies:
flutter_umeng_ushare:
path: ../flutter_umeng_ushare
if (Platform.isAndroid) {
//初始化友盟
UMengShare.initUMConfigure("606c5c04de41b946ab3fa67a", "io.youyi.cashier");
} else if (Platform.isIOS) {
UMengShare.initUMConfigure("606c5c04de41b946ab3fa67a", "io.youyi.cashier");
}
//微信配置
UMengShare.initPlatformConfig(UMPlatform.Wechat, "wx0a72b9202cea7d69",
"37395a00a62d87f255b23b1421XXXXXX", "universal link");
//QQ配置
UMengShare.initPlatformConfig(
UMPlatform.QQ, "1106280000", "HWol57Eo2qXXXXXX", "universal link");
UMengShare.shareText(UMSharePlatform.Qzone, "test 分享");
UMengShare.shareImage(
UMSharePlatform.QQ,
"https://pics3.baidu.com/feed/b3119313b07eca801b8cf7a23199d9d5a0448329.png?token=81d3401ccb1a44a9dc5adf27d2567c75",
"https://pics3.baidu.com/feed/b3119313b07eca801b8cf7a23199d9d5a0448329.png?token=81d3401ccb1a44a9dc5adf27d2567c75",
);
UMengShare.shareMedia(
UMSharePlatform.QQ,
UMShareMediaType.WebUrl,
"分享的标题",
"分享的说明内容",
"https://pics3.baidu.com/feed/b3119313b07eca801b8cf7a23199d9d5a0448329.png?token=81d3401ccb1a44a9dc5adf27d2567c75",
"https://www.beyongx.com/",
);
UMengShare.login(UMPlatform.QQ);
看文档 https://developer.umeng.com/docs/128606/detail/193879
需要在主项目 > android模块 中操作:
- 新增包 ${package_name}.wxapi;
- 新建 WXCallbackActivity.java,内容如下(记得替换${package_name});
package ${package_name}.wxapi;
import com.umeng.socialize.weixin.view.WXCallbackActivity;
public class WXEntryActivity extends WXCallbackActivity {
}
注:需要在主项目 > android模块增加qqappid配置: 定位文件:/android/app/build.gradle
defaultConfig {
....
manifestPlaceholders = [qqappid: "1106280000"]
}
看文档 https://developer.umeng.com/docs/128606/detail/193653
info.plist添加:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wechat</string>
<string>weixin</string>
<string>weixinULAPI</string>
<string>mqqopensdklaunchminiapp</string>
<string>mqqopensdkminiapp</string>
<string>mqqapi</string>
<string>mqq</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqconnect</string>
<string>mqqopensdkdataline</string>
<string>mqqopensdkgrouptribeshare</string>
<string>mqqopensdkfriend</string>
<string>mqqopensdkapi</string>
<string>mqqopensdkapiV2</string>
<string>mqqopensdkapiV3</string>
<string>mqqopensdkapiV4</string>
<string>mqzoneopensdk</string>
<string>wtloginmqq</string>
<string>wtloginmqq2</string>
<string>mqqwpa</string>
<string>mqzone</string>
<string>mqzonev2</string>
<string>mqzoneshare</string>
<string>wtloginqzone</string>
<string>mqzonewx</string>
<string>mqzoneopensdkapiV2</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapi</string>
<string>mqqbrowser</string>
<string>mttbrowser</string>
<string>tim</string>
<string>timapi</string>
<string>timopensdkfriend</string>
<string>timwpa</string>
<string>timgamebindinggroup</string>
<string>timapiwallet</string>
<string>timOpensdkSSoLogin</string>
<string>wtlogintim</string>
<string>timopensdkgrouptribeshare</string>
<string>timopensdkapiV4</string>
<string>timgamebindinggroup</string>
<string>timopensdkdataline</string>
<string>wtlogintimV1</string>
<string>timapiV1</string>
</array>
项目 targets -> info -> URL Types 中添加:
- QQ配置1: identifier: qq1, URL Schemes: tencent${qq_conn_appId}
- QQ配置2: identifier: qq2, URL Schemes: QQ${qq_conn_appId转16进制,结果不足8位前面补零}
- 微信设置:identifier: weixin, URL Schemes: ${weixin_appId}
- app developer后台enable Associated Domains;
- xcode中设置 targets->Capabilites->Associated Domains,设置:applinks:your_domain; 3)your_domain根目录下配置 apple-app-site-association, 注意须https nginx设置:
server {
listen 443 ssl;
server_name your_domain;
# 需添加的内容,apple会进行验证,实现app之间的跳转;记得替换:${apple_team_ID},${bundle_id},${weixin_path},${qq_conn_appid}
location /apple-app-site-association {
charset UTF-8;
default_type text/html;
return 200 '{\"applinks\":{\"apps\":[],\"details\":[{\"appID\":\"${apple_team_id}.${bundle_id}\",\"paths\":[\"/${weixin_path}/*\",\"/qq_conn/${qq_conn_appid}/*\"]}]}}';
}
}
apple提供的网页验证地址:https://search.developer.apple.com/appsearch-validation-tool/
Object-C:
// 支持所有iOS系统
-(BOOL)application:(UIApplication*)application handleOpenURL:(NSURL *)url
{
BOOL result =[[UMSocialManager defaultManager] handleOpenURL:url];
if (!result) {
// 其他如支付等SDK的回调
}
return result;
}
-(BOOL)application:(UIApplication*)application continueUserActivity:(NSUserActivity*)userActivity restorationHandler:(void(^)(NSArray* __nullable restorableObjects))restorationHandler
{
if(![[UMSocialManager defaultManager] handleUniversalLink:userActivity options:nil]){
// 其他SDK的回调
}
return YES;
}
Swift:
//设置url/Scheme自定义的url系统回调
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("open url: \(url.absoluteString)")
let result = UMSocialManager.default().handleOpen(url, options: options)
if (!result) {
// 其他如支付等SDK的回调
}
//let result = UmengShareFlutterIos.handleOpen(url, options: options)
print("result: \(result)")
return result
}
//设置Universal Links系统回调
override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
print("continue userActivity: \(userActivity)")
let result = UMSocialManager.default().handleUniversalLink(userActivity, options: nil)
print("result: \(result)")
return true
}
在lib/umeng_share.dart可以查看到:
UMengShare.shareText(UMSharePlatform platform,String text)
UMengShare.shareImage(UMSharePlatform platform,String thumb,String image)
UMengShare.shareMedia(UMSharePlatform platform,UMShareMediaType type,String title,String desc,String thumb,String link)
UMengShare.shareMiniApp(String username,String title,String desc,String thumb,String url,String path)
UMengShare.login(UMPlatform platform)
UMengShare.checkInstall(UMPlatform platform)
UMengShare.login(UMPlatform.QQ);
UMengShare.checkInstall(UMSharePlatform.QQ);
UMengShare.checkInstall(UMSharePlatform.WECHAT);