1、注冊(cè)ShareSDK的賬號(hào) 創(chuàng)建應(yīng)用
創(chuàng)建應(yīng)用 獲取應(yīng)用的App Key和App Secret 具體步驟參考官方文檔 講的很詳細(xì)http://bbs.mob.com/forum.php?mod=viewthread&tid=8212&extra=page%3D1
2.下載SDK 也可使用 cocoaPods 集成
官方文檔上有詳細(xì)的注釋?zhuān)绻謩?dòng)導(dǎo)包 請(qǐng)仔細(xì)閱讀根據(jù)文檔一步步操作。
http://wiki.mob.com/ios%E7%AE%80%E6%B4%81%E7%89%88%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/
3.SSO(免登錄)設(shè)置
配置QQ所需的配置需要轉(zhuǎn)格式 其他平臺(tái)的設(shè)置參照文檔
在URL Types中添加QQ的AppID,其格式為:”QQ” + AppId的16進(jìn)制(如果appId轉(zhuǎn)換的16進(jìn)制數(shù)不夠8位則在前面補(bǔ)0,如轉(zhuǎn)換的是:5FB8B52,則最終填入為:QQ05FB8B52 注意:轉(zhuǎn)換后的字母要大寫(xiě)) 轉(zhuǎn)換16進(jìn)制的方法:echo ‘ibase=10;obase=16;801312852′|bc,其中801312852為QQ的AppID,見(jiàn)下圖

URL Types配置 以微信為例:

4.設(shè)置ShareSDK的Appkey并初始化對(duì)應(yīng)的第三方社交平臺(tái)
打開(kāi)AppDelegate.m導(dǎo)入頭文件(根據(jù)自己的需求)
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKConnector/ShareSDKConnector.h>
//騰訊開(kāi)放平臺(tái)(對(duì)應(yīng)QQ和QQ空間)SDK頭文件
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>
//微信SDK頭文件
#import "WXApi.h"
//新浪微博SDK頭文件
#import "WeiboSDK.h"
//新浪微博SDK需要在項(xiàng)目Build Settings中的Other Linker Flags添加"-ObjC"
//人人SDK頭文件
#import <RennSDK/RennSDK.h>
在- (BOOL)application: didFinishLaunchingWithOptions:方法中調(diào)用registerApp方法來(lái)初始化SDK并且初始化第三方平臺(tái)(ShareSDK各社交平臺(tái)申請(qǐng)APPkey 的網(wǎng)址及申請(qǐng)流程匯總http://bbs.mob.com/forum.php?mod=viewthread&tid=275&page=1&extra=#pid860)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/**
* 設(shè)置ShareSDK的appKey,如果尚未在ShareSDK官網(wǎng)注冊(cè)過(guò)App,請(qǐng)移步到http://mob.com/login 登錄后臺(tái)進(jìn)行應(yīng)用注冊(cè)
* 在將生成的AppKey傳入到此方法中。
* 方法中的第二個(gè)第三個(gè)參數(shù)為需要連接社交平臺(tái)SDK時(shí)觸發(fā),
* 在此事件中寫(xiě)入連接代碼。第四個(gè)參數(shù)則為配置本地社交平臺(tái)時(shí)觸發(fā),根據(jù)返回的平臺(tái)類(lèi)型來(lái)配置平臺(tái)信息。
* 如果您使用的時(shí)服務(wù)端托管平臺(tái)信息時(shí),第二、四項(xiàng)參數(shù)可以傳入nil,第三項(xiàng)參數(shù)則根據(jù)服務(wù)端托管平臺(tái)來(lái)決定要連接的社交SDK。
*/
[ShareSDK registerApp:@"iosv1101"
activePlatforms:@[
@(SSDKPlatformTypeSinaWeibo),
@(SSDKPlatformTypeMail),
@(SSDKPlatformTypeSMS),
@(SSDKPlatformTypeCopy),
@(SSDKPlatformTypeWechat),
@(SSDKPlatformTypeQQ),
@(SSDKPlatformTypeRenren),
@(SSDKPlatformTypeGooglePlus)]
onImport:^(SSDKPlatformType platformType)
{
switch (platformType)
{
case SSDKPlatformTypeWechat:
[ShareSDKConnector connectWeChat:[WXApi class]];
break;
case SSDKPlatformTypeQQ:
[ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
break;
case SSDKPlatformTypeSinaWeibo:
[ShareSDKConnector connectWeibo:[WeiboSDK class]];
break;
case SSDKPlatformTypeRenren:
[ShareSDKConnector connectRenren:[RennClient class]];
break;
default:
break;
}
}
onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
{
switch (platformType)
{
case SSDKPlatformTypeSinaWeibo:
//設(shè)置新浪微博應(yīng)用信息,其中authType設(shè)置為使用SSO+Web形式授權(quán)
[appInfo SSDKSetupSinaWeiboByAppKey:@"568898243"
appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
redirectUri:@"http://www.sharesdk.cn"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeWechat:
[appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"
appSecret:@"64020361b8ec4c99936c0e3999a9f249"];
break;
case SSDKPlatformTypeQQ:
[appInfo SSDKSetupQQByAppId:@"100371282"
appKey:@"aed9b0303e3ed1e27bae87c33761161d"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeRenren:
[appInfo SSDKSetupRenRenByAppId:@"226427"
appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
secretKey:@"f29df781abdd4f49beca5a2194676ca4"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeGooglePlus:
[appInfo SSDKSetupGooglePlusByClientID:@"232554794995.apps.googleusercontent.com"
clientSecret:@"PEdFgtrMw97aCvf0joQj7EMk"
redirectUri:@"http://localhost"];
break;
default:
break;
}
}];
return YES;
}
4.添加實(shí)現(xiàn)代碼
打開(kāi)需要集成分享功能的視圖源碼,把如下代碼復(fù)制并粘貼到你要分享的位置,例如到響應(yīng)分享按鈕的方法中。并且修改相應(yīng)的參數(shù)即可。
1.需要在分享的試圖中導(dǎo)入的頭文件
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
2.調(diào)用構(gòu)造分享參數(shù)接口和分享的接口
//1、創(chuàng)建分享參數(shù)
NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];
//(注意:圖片必須要在Xcode左邊目錄里面,名稱(chēng)必須要傳正確,如果要分享網(wǎng)絡(luò)圖片,可以這樣傳iamge參數(shù) images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"])
if (imageArray) {
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:@"分享內(nèi)容"
images:imageArray
url:[NSURL URLWithString:@"http://mob.com"]
title:@"分享標(biāo)題"
type:SSDKContentTypeAuto];
//2、分享(可以彈出我們的分享菜單和編輯界面)
[ShareSDK showShareActionSheet:nil //要顯示菜單的視圖, iPad版中此參數(shù)作為彈出菜單的參照視圖,只有傳這個(gè)才可以彈出我們的分享菜單,可以傳分享的按鈕對(duì)象或者自己創(chuàng)建小的view 對(duì)象,iPhone可以傳nil不會(huì)影響
items:nil
shareParams:shareParams
onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
switch (state) {
case SSDKResponseStateSuccess:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
message:nil
delegate:nil
cancelButtonTitle:@"確定"
otherButtonTitles:nil];
[alertView show];
break;
}
case SSDKResponseStateFail:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失敗"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
break;
}
default:
break;
}
}
];}
5.最后一定要看的 防止掉坑里 !!!
適配iOS9系統(tǒng)注意點(diǎn):
1.大部分社交平臺(tái)接口不支持https協(xié)議
2.小部分社交平臺(tái)SDK不支持bitcode
3.添加Scheme白名單
http://wiki.mob.com/ios9-%E5%AF%B9sharesdk%E7%9A%84%E5%BD%B1%E5%93%8D%EF%BC%88%E9%80%82%E9%85%8Dios-9%E5%BF%85%E8%AF%BB%EF%BC%89/
4.本人遇到的問(wèn)題:

解決方法 將微信添加白名單
5.關(guān)于分享界面是英文的問(wèn)題
如下配置:
添加Language
