今天碰到了ShareSDK,虽然使用很简单,但是也入了很多坑,下面就详细的记录一下。
ShareSDK是一个第三方库,包括了分享,第三方登录等,官网地址:http://www.mob.com。具体步骤可查看http://wiki.mob.com/ios简洁版快速集成/。在配置完成后,在AppDelegate.m文件中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions下,添加
[ShareSDK registerApp:@"Your ShareSDK AppID"//自己在shareSDK官网注册的appid activePlatforms:@[@(SSDKPlatformTypeQQ), @(SSDKPlatformTypeWechat), @(SSDKPlatformTypeSinaWeibo) ] onImport:^(SSDKPlatformType platformType) { switch (platformType) { case SSDKPlatformTypeQQ: [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]]; break; case SSDKPlatformTypeWechat: [ShareSDKConnector connectWeChat:[WXApi class]]; break; case SSDKPlatformTypeSinaWeibo: [ShareSDKConnector connectWeibo:[WeiboSDK class]]; break; default: break; } } onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) { switch (platformType) { case SSDKPlatformTypeQQ: [appInfo SSDKSetupQQByAppId:kQQAppId appKey:kQQAppSecret authType:SSDKAuthTypeBoth]; break; case SSDKPlatformTypeWechat: [appInfo SSDKSetupWeChatByAppId:kWXAppId appSecret:kWXAppSecret]; break; case SSDKPlatformTypeSinaWeibo: [appInfo SSDKSetupSinaWeiboByAppKey:kWBAppId appSecret:kWBAppSecret redirectUri:@"http://www.baidu.com" authType:SSDKAuthTypeBoth]; break; default: break; } }];
坑点:QQAppId,WXAppId,WBAppId为在QQ,微信,微博各自的平台上注册应用后给的id号,接入应用需要审核时间。
在点击对应图标登录的方法下添加如下代码 (以微信为例),
[ShareSDK getUserInfo:SSDKPlatformTypeWechat onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error){}
在ios9后出现了白名单一说,为了能让自己的应用搜索到手机上是否安装了对应的软件,应在
并且在info.plist中添加(根据需要自行增删)
LSApplicationQueriesSchemes sinaweibo sinaweibohd sinaweibosso sinaweibohdsso weixin mqqOpensdkSSoLogin mqqopensdkapiV2 mqqopensdkapiV3 wtloginmqq2 mqq mqqapi