Unity接入友盟分享遇到的坑

  最近项目接了一下友盟分享的SDK,中间遇到了几个坑,写下几条注意事项记录一下。

  接入之前需要准备友盟开发者账号,相应平台开发者账号(微信、QQ、新浪微博)等...

 

安卓端:

  1、确保 AndroidManifest.xml 中声名了相应权限(网络权限、获取已安装应用等)一般平台官方文档会写明所需权限

  2、在 AndroidManifest.xml 内声明相应Activity,例如微信分享(xxx.wxapi.WXEntryActivity,xxx为apk完整包名),QQ授权(com.tencent.tauth.AuthActivity)等,并确保声明无误

  3、在调用分享之前,必须初始化平台参数,友盟AppID,以及对于平台appid,AppSecret等参数,每个平台参数不一致,查看官方文档确定,可以直接把参数放在 xml 的 meta-data 上 Application 启动后的 onCreate 方法中进行初始化,具体逻辑根据项目来确定。 

 1 @Override
 2     public void onCreate() {
 3         super.onCreate();
 4         UMConfigure.init(this,"5a12384aa40fa3551f0001d1","umeng",UMConfigure.DEVICE_TYPE_PHONE,"");
 5         PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0");
 6         //豆瓣RENREN平台目前只能在服务器端配置
 7         PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad","http://sns.whalecloud.com");
 8         PlatformConfig.setYixin("yxc0614e80c9304c11b0391514d09f13bf");
 9         PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
10         PlatformConfig.setTwitter("3aIN7fuF685MuZ7jtXkQxalyi", "MK6FEYG63eWcpDFgRYw4w9puJhzDl0tyuqWjZ3M7XJuuG7mMbO");
11         PlatformConfig.setAlipay("2015111700822536");
12         PlatformConfig.setLaiwang("laiwangd497e70d4", "d497e70d4c3e4efeab1381476bac4c5e");
13         PlatformConfig.setPinterest("1439206");
14         PlatformConfig.setKakao("e4f60e065048eb031e235c806b31c70f");
15         PlatformConfig.setDing("dingoalmlnohc0wggfedpk");
16         PlatformConfig.setVKontakte("5764965","5My6SNliAaLxEm3Lyd9J");
17         PlatformConfig.setDropbox("oz8v5apet3arcdy","h7p2pjbzkkxt02a");
18         PlatformConfig.setYnote("9c82bf470cba7bd2f1819b0ee26f86c6ce670e9b");
19     }
初始化

  或许你在一切都准备好之后,兴致冲冲的打包,安装,点击分享,QQ好友,成功。QQ空间,成功。感觉完成了重要使命,hahaha。然后点击微信,没反应(或者闪一下),what??? 一顿调试之后,无果,fuck!!!   按下面步骤查一下吧:

    (1)  查看微信后台包名是否和应用包名一致(微信开放平台  ==》 管理中心   ==》 点击查看  ==》 开发信息  ),包括appid,AppSecret 等。

    (2)  下载工具 (传送门)安装到手机,查看一下打包到手机的apk签名是不是和后台一致,不一致就更换相应签名证书,或者更改后台信息。

    (3)  如果只能正确分享,收不到回调,查看 WXEntryActivity 再三查看配置的是不是正确吧。

1  <activity
2             android:name=".wxapi.WXEntryActivity"
3             android:configChanges="keyboardHidden|orientation|screenSize"
4             android:exported="true"
5             android:theme="@android:style/Theme.Translucent.NoTitleBar" />
微信回调

 

苹果端:

  1、Unity3D导出到Xcode,打开 Info.plist 文件,或者 Info 里设置 URL Types 设置相应平台所需appid,具体设置规则查看官方文档。

  2、Info.plist 里设置SSO白名单,不然无法进行应用间跳转,同样规则看文档

  1 <key>LSApplicationQueriesSchemeskey>
  2 <array>
  3     
  4     <string>wechatstring>
  5     <string>weixinstring>
  6 
  7     
  8     <string>sinaweibohdstring>
  9     <string>sinaweibostring>
 10     <string>sinaweibossostring>
 11     <string>weibosdkstring>
 12     <string>weibosdk2.5string>
 13 
 14     
 15     <string>mqqapistring>
 16     <string>mqqstring>
 17     <string>mqqOpensdkSSoLoginstring>
 18     <string>mqqconnectstring>
 19     <string>mqqopensdkdatalinestring>
 20     <string>mqqopensdkgrouptribesharestring>
 21     <string>mqqopensdkfriendstring>
 22     <string>mqqopensdkapistring>
 23     <string>mqqopensdkapiV2string>
 24     <string>mqqopensdkapiV3string>
 25     <string>mqqopensdkapiV4string>
 26     <string>mqzoneopensdkstring>
 27     <string>wtloginmqqstring>
 28     <string>wtloginmqq2string>
 29     <string>mqqwpastring>
 30     <string>mqzonestring>
 31     <string>mqzonev2string>
 32     <string>mqzonesharestring>
 33     <string>wtloginqzonestring>
 34     <string>mqzonewxstring>
 35     <string>mqzoneopensdkapiV2string>
 36     <string>mqzoneopensdkapi19string>
 37     <string>mqzoneopensdkapistring>
 38     <string>mqqbrowserstring>
 39     <string>mttbrowserstring>
 40     <string>timstring>
 41     <string>timapistring>
 42     <string>timopensdkfriendstring>
 43     <string>timwpastring>
 44     <string>timgamebindinggroupstring>
 45     <string>timapiwalletstring>
 46     <string>timOpensdkSSoLoginstring>
 47     <string>wtlogintimstring>
 48     <string>timopensdkgrouptribesharestring>
 49     <string>timopensdkapiV4string>
 50     <string>timgamebindinggroupstring>
 51     <string>timopensdkdatalinestring>
 52     <string>wtlogintimV1string>
 53     <string>timapiV1string>
 54 
 55     
 56     <string>alipaystring>
 57     <string>alipaysharestring>
 58 
 59     
 60       <string>dingtalkstring>
 61       <string>dingtalk-openstring>
 62 
 63     
 64     <string>linkedinstring>
 65     <string>linkedin-sdk2string>
 66     <string>linkedin-sdkstring>
 67 
 68     
 69     <string>laiwangssostring>
 70 
 71     
 72     <string>yixinstring>
 73     <string>yixinopenapistring>
 74 
 75     
 76     <string>instagramstring>
 77 
 78     
 79     <string>whatsappstring>
 80 
 81     
 82     <string>linestring>
 83 
 84     
 85     <string>fbapistring>
 86     <string>fb-messenger-apistring>
 87     <string>fb-messenger-share-apistring>
 88     <string>fbauth2string>
 89     <string>fbshareextensionstring>
 90 
 91       
 92      
 93         
 94     <string>kakaofa63a0b2356e923f3edd6512d531f546string>
 95     <string>kakaokompassauthstring>
 96     <string>storykompassauthstring>
 97     <string>kakaolinkstring>
 98     <string>kakaotalk-4.5.0string>
 99     <string>kakaostory-2.9.0string>
100 
101      
102     <string>pinterestsdk.v1string>
103 
104      
105     <string>tumblrstring>
106 
107    
108     <string>evernotestring>
109     <string>enstring>
110     <string>enxstring>
111     <string>evernotecidstring>
112     <string>evernotemsgstring>
113 
114    
115     <string>youdaonotestring>
116     <string>ynotedictfavstring>
117     <string>com.youdao.note.todayViewNotestring>
118     <string>ynotesharesdkstring>
119 
120    
121     <string>gplusstring>
122 
123    
124     <string>pocketstring>
125     <string>readitlaterstring>
126     <string>pocket-oauth-v1string>
127     <string>fb131450656879143string>
128     <string>en-readitlater-5776string>
129     <string>com.ideashower.ReadItLaterPro3string>
130     <string>com.ideashower.ReadItLaterProstring>
131     <string>com.ideashower.ReadItLaterProAlphastring>
132     <string>com.ideashower.ReadItLaterProEnterprisestring>
133 
134    
135     <string>vkstring>
136     <string>vk-sharestring>
137     <string>vkauthorizestring>
138 
139    
140     <string>twitterstring>
141     <string>twitterauthstring>
142 array>
SSO白名单

  3、其他权限,比如相册访问等,添加相应权限

  4、Build Settings 里设置 Other Linker Flags 添加 -ObjC (注意大小写)

  5、调用分享之前在代码中初始化平台appid,AppSecret 等参数,初始化位置根据项目要求调整

  6、在 UnityAppContriller 中设置回调

1 - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
2 {
3     BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
4     if (!result) {
5         // 其他如支付等SDK的回调
6     }
7     return result;
8 }
分享回调

  或者添加自定义脚本

#import "UnityAppController.h"
#import 

@interface AppControllerWithShare : UnityAppController
    
@end

IMPL_APP_CONTROLLER_SUBCLASS (AppControllerWithShare)


@implementation AppControllerWithShare

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionaryid> *)options
{
    //6.3的新的API调用,是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
    BOOL result = [[UMSocialManager defaultManager]  handleOpenURL:url options:options];
    if (!result) {
        // 其他如支付等SDK的回调
    }
    return result;
}


- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
    if (!result) {
        // 其他如支付等SDK的回调
    }
    return result;
}

@end
自定义回调

  IMPL_APP_CONTROLLER_SUBCLASS (AppControllerWithShare)  

  此行作用就是把 AppControllerWithShare 作为启动入口

  

 

转载于:https://www.cnblogs.com/ikay/p/9642417.html

你可能感兴趣的:(游戏)