這是shareSDK iOS文檔的地址http://wiki.mob.com/ios簡潔版快速集成/,整個shareSDK需要添加的靜態包和添加的文件都有說明,我主要說一下我在開發中遇到的一些問題。
1.在騰訊、新浪的官方申請appKey和appSecret的時候,申請的項目必須在騰訊和新浪的官方審核通過,因為沒有通過審核,我們在編寫代碼的時候就不能用appKey和appSecret進行開發。
2.新浪微博SDK需要在項目的Build Settings中的Other Linker Flags添加”-ObjC”。
3.QQ開發在URL Types中添加QQ的AppID,其格式為:”QQ” + AppId的16進制。
//第三方登錄(QQ、微信、新浪)
/*
* 設置ShareSDK的appKey,如果尚未在ShareSDK官網注冊過App,請移步 到http://mob.com/login登錄后臺進行應用注冊,
* 在將生成的AppKey傳入到此方法中。
* 方法中的第二個第三個參數為需要連接社交平臺SDK時觸發,
* 在此事件中寫入連接代碼。第四個參數則為配置本地社交平臺時觸發,根據返回的平臺類型來配置平臺信息。
* 如果您使用的時服務端托管平臺信息時,第二、四項參數可以傳入nil,第三項參數則根據服務端托管平臺來決定要連接的社交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;
}
}];
//分享具體的參數作用我沒有寫,在shareSDK中介紹的非常詳細了,如果分享沒有圖片,url的內置鏈接就不能起到作用。
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:@""];
//短信分享(記得開始的時候注冊)
[shareParams SSDKSetupSMSParamsByText:@"" title:@"" images:nil attachments:nil recipients:nil type:SSDKContentTypeText];
**短信分享可能出現卡死的問題,可能和使用了IQKeyboardManager第三方框架有關系,只要關閉鍵盤彈出就沒有問題了。
[[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];