用ShareSDK 進(jìn)行第三方分享
1.首先要先注冊自己的appkey在shareSDK官網(wǎng)里面
2.下載shareSDK 文檔,可以根據(jù)需要下載自己需要的
如圖

3.將下載好的shareSDK 解壓后加入工程里面
4.添加依賴庫

//必須添加的庫
必須添加的依賴庫如下(Xcode 7 下 .dylib庫后綴名更改為.tbd):
libicucore.dylib
libz.dylib
libstdc++.dylib
JavaScriptCore.framework
新浪微博SDK依賴庫
ImageIO.framework
libsqlite3.dylib
QQ好友和QQ空間SDK依賴庫
libsqlite3.dylib
微信SDK依賴庫
libsqlite3.dylib
短信和郵件需要依賴庫
MessageUI.framework
5.打開*AppDelegate.m
導(dǎo)入需要的頭文件 如圖

6.在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions里面添加代碼
- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
{
/-
設(shè)置ShareSDK的appKey,如果尚未在ShareSDK官網(wǎng)注冊過App,請移步到http://mob.com/login 登錄后臺進(jìn)行應(yīng)用注冊
-
在將生成的AppKey傳入到此方法中。
-
方法中的第二個(gè)第三個(gè)參數(shù)為需要連接社交平臺SDK時(shí)觸發(fā),
-
在此事件中寫入連接代碼。第四個(gè)參數(shù)則為配置本地社交平臺時(shí)觸發(fā),根據(jù)返回的平臺類型來配置平臺信息。
-
如果您使用的時(shí)服務(wù)端托管平臺信息時(shí),第二、四項(xiàng)參數(shù)可以傳入nil,第三項(xiàng)參數(shù)則根據(jù)服務(wù)端托管平臺來決定要連接的社交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;
}
-
7.在你點(diǎn)擊方法里面加入代碼
//1、創(chuàng)建分享參數(shù)
NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];
(注意:圖片必須要在Xcode左邊目錄里面,名稱必須要傳正確,如果要分享網(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è)才可以彈出我們的分享菜單,可以傳分享的按鈕對象或者自己創(chuàng)建小的view 對象,iPhone可以傳nil不會影響
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;
}
}
];}
8.SSO授權(quán)登錄

注。。。。。。。QQ的SSO授權(quán)的 URL Schemes 的 appkey 為16進(jìn)制;微博分享需要在開發(fā)者賬號上面申請應(yīng)用,拿到ID,在微博開放平臺上面相應(yīng)地址填上就可以申請了。
你想要在哪個(gè)應(yīng)用上面分享,你就要去哪個(gè)應(yīng)用的開發(fā)平臺申請應(yīng)用,拿到相應(yīng)的appkey 和 appSecret.
完畢——————。

浙公網(wǎng)安備 33010602011771號