這是shareSDK iOS文檔的地址http://wiki.mob.com/ios簡(jiǎn)潔版快速集成/,整個(gè)shareSDK需要添加的靜態(tài)包和添加的文件都有說明,我主要說一下我在開發(fā)中遇到的一些問題。
1.在騰訊、新浪的官方申請(qǐng)appKey和appSecret的時(shí)候,申請(qǐng)的項(xiàng)目必須在騰訊和新浪的官方審核通過,因?yàn)闆]有通過審核,我們?cè)诰帉懘a的時(shí)候就不能用appKey和appSecret進(jìn)行開發(fā)。
2.新浪微博SDK需要在項(xiàng)目的Build Settings中的Other Linker Flags添加”-ObjC”。
3.QQ開發(fā)在URL Types中添加QQ的AppID,其格式為:”QQ” + AppId的16進(jìn)制。

//第三方登錄(QQ、微信、新浪)
/*
* 設(shè)置ShareSDK的appKey,如果尚未在ShareSDK官網(wǎng)注冊(cè)過App,請(qǐng)移步 到http://mob.com/login登錄后臺(tái)進(jìn)行應(yīng)用注冊(cè),
* 在將生成的AppKey傳入到此方法中。
* 方法中的第二個(gè)第三個(gè)參數(shù)為需要連接社交平臺(tái)SDK時(shí)觸發(fā),
* 在此事件中寫入連接代碼。第四個(gè)參數(shù)則為配置本地社交平臺(tái)時(shí)觸發(fā),根據(jù)返回的平臺(tái)類型來配置平臺(tái)信息。
* 如果您使用的時(shí)服務(wù)端托管平臺(tái)信息時(shí),第二、四項(xiàng)參數(shù)可以傳入nil,第三項(xiàng)參數(shù)則根據(jù)服務(wù)端托管平臺(tái)來決定要連接的社交SDK。
*/
[ShareSDK registerApp:@""
activePlatforms:@[
@(SSDKPlatformTypeSinaWeibo),
@(SSDKPlatformTypeWechat),
@(SSDKPlatformTypeQQ)]
onImport:^(SSDKPlatformType platformType)
{
switch (platformType)
{
case SSDKPlatformTypeSinaWeibo:
[ShareSDKConnector connectWeibo:[WeiboSDK class]];
break;
case SSDKPlatformTypeQQ:
[ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
break;
case SSDKPlatformTypeWechat:
[ShareSDKConnector connectWeChat:[WXApi class]];
break;
default:
break;
}
}
onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
{
switch (platformType)
{
case SSDKPlatformTypeSinaWeibo:
[appInfo SSDKSetupSinaWeiboByAppKey:@"appKey" appSecret:@"appSecret" redirectUri:@"http://open.weibo.com/" authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeQQ:
[appInfo SSDKSetupQQByAppId:@"" appKey:@"" authType:SSDKAuthTypeSSO];
break;
case SSDKPlatformTypeWechat:
[appInfo SSDKSetupWeChatByAppId:@"" appSecret:@""];
break;
default:
break;
}
}];
//分享具體的參數(shù)作用我沒有寫,在shareSDK中介紹的非常詳細(xì)了,如果分享沒有圖片,url的內(nèi)置鏈接就不能起到作用。
NSMutableDictionary *shareParams = [NSMutableDictionary new];
//新浪分享
[shareParams SSDKSetupSinaWeiboShareParamsByText:@"" title:@"" image:@"" url:@"" latitude:@"" longitude:@"" objectID:@"" type:@""];
//微信分享
[shareParams SSDKSetupWeChatParamsByText:@"" title:@"" url:@"" thumbImage:@"" image:@"" musicFileURL:@"" extInfo:@"" fileData:@"" emoticonData:@"" type:@"" forPlatformSubType:@""];
//QQ分享
[shareParams SSDKSetupQQParamsByText:@"" title:@"" url:@"" thumbImage:@"" image:@"" type:@"" forPlatformSubType:@""];
//短信分享(記得開始的時(shí)候注冊(cè))
[shareParams SSDKSetupSMSParamsByText:@"" title:@"" images:nil attachments:nil recipients:nil type:SSDKContentTypeText];
**短信分享可能出現(xiàn)卡死的問題,可能和使用了IQKeyboardManager第三方框架有關(guān)系,只要關(guān)閉鍵盤彈出就沒有問題了。
[[IQKeyboardManager sharedManager] setEnable:NO];//注意加
[ShareSDK share:SSDKPlatformTypeSMS parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
[[IQKeyboardManager sharedManager] setEnable:YES];//注意加
if (state == SSDKResponseStateSuccess) {
[[[UIApplication sharedApplication].delegate window] makeToast:@"分享成功" duration:2 position:@"center"];
}else{
[[[UIApplication sharedApplication].delegate window] makeToast:@"分享失敗" duration:2 position:@"center"];
}
}];
//郵件分享
[shareParams SSDKSetupMailParamsByText:@"" title:@"" images:@"" attachments:nil recipients:nil ccRecipients:nil bccRecipients:nil type:SSDKContentTypeAuto];