使用shareSDk進(jìn)行第三方分享

一、下載導(dǎo)入

1.進(jìn)入mob官網(wǎng)(mob.com)下載自己需要的shareSDK。

2.將下載后的文件(.tar.gz)格式改為zip格式后,解壓。

3.將文件導(dǎo)入項(xiàng)目中。

二、項(xiàng)目配置

1.添加依賴庫(具體參照官網(wǎng)添加依賴庫步驟)

2.添加shareSDK的AppKey,以及實(shí)現(xiàn)代碼。

在appdelegate.m中

(1)導(dǎo)入類庫

//第三方分享

#import <ShareSDK/ShareSDK.h>

#import <ShareSDKConnector/ShareSDKConnector.h>

//騰訊開放平臺(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"


(2)在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中實(shí)現(xiàn)的代碼

[ShareSDK registerApp:@"1d7970589ec14" activePlatforms:@[@(SSDKPlatformTypeSinaWeibo),@(SSDKPlatformSubTypeQZone),@(SSDKPlatformTypeSMS),@(SSDKPlatformTypeCopy),//@(SSDKPlatformSubTypeWechatSession),//@(SSDKPlatformSubTypeWechatTimeline),@(SSDKPlatformSubTypeQQFriend),@(SSDKPlatformSubTypeWechatFav)] ?

?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 SSDKPlatformSubTypeQZone:

break;

case SSDKPlatformTypeSMS:

break;

case SSDKPlatformTypeCopy:

break;

//case SSDKPlatformSubTypeWechatSession:

//break;

//case SSDKPlatformSubTypeWechatTimeline:

//break;

case SSDKPlatformSubTypeQQFriend:

break;

case SSDKPlatformSubTypeWechatFav:

break;

default:

break;

}

}

onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)

{

switch (platformType)

{

case SSDKPlatformTypeSinaWeibo:

//設(shè)置新浪微博應(yīng)用信息,其中authType設(shè)置為使用SSO+Web形式授權(quán)

[appInfo SSDKSetupSinaWeiboByAppKey:@"979793039" appSecret:@"146adc5f73eced0654b711bdb4b18cac" redirectUri:@"http://msskd.com"? authType:SSDKAuthTypeBoth];

break;

case SSDKPlatformTypeWechat:

[appInfo SSDKSetupWeChatByAppId:@"wx8970561dd448bd02"

appSecret:@""];

break;

case SSDKPlatformTypeQQ:

[appInfo SSDKSetupQQByAppId:@"1106058709" appKey:@"L1Oz6KYzx2F6nHGl" authType:SSDKAuthTypeBoth];

default:

break;

}

}];

(3)在實(shí)現(xiàn)分享頁面點(diǎn)擊按鈕方法中代碼

[1]導(dǎo)入shareSDK的類庫

#import <ShareSDK/ShareSDK.h>

#import <ShareSDKUI/ShareSDK+SSUI.h>

[2]使用系統(tǒng)UI界面實(shí)現(xiàn)代碼

//1、創(chuàng)建分享參數(shù)

NSArray* imageArray = @[[UIImage imageNamed:@"appIcon.png"]];

//(注意:圖片必須要在Xcode左邊目錄里面,名稱必須要傳正確,如果要分享網(wǎng)絡(luò)圖片,可以這樣傳iamge參數(shù) images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"])

if (imageArray)

{

NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];

//允許客戶端進(jìn)行分享

[shareParams SSDKEnableUseClientShare];

//自動(dòng)設(shè)置的分享內(nèi)容

//[shareParams SSDKSetupShareParamsByText:@"分享內(nèi)容"? images:imageArray? url:[NSURL URLWithString:@"http://msskd.com"] title:@"分享標(biāo)題" type:SSDKContentTypeWebPage];

//單獨(dú)設(shè)置的不同平臺(tái)分享內(nèi)容

[shareParams SSDKSetupQQParamsByText:@"同城-專人-直送-4元起! 代取、代送、代買、代辦事,順風(fēng)件~? 微信公眾號(hào)-app均可下單" title:@"鄭州人都在用的跑腿APP" url:[NSURL URLWithString:userQRCodeString] thumbImage:[UIImage imageNamed:@"appIcon.png"] image:[UIImage imageNamed:@"appIcon.png"] type:SSDKContentTypeWebPage forPlatformSubType:SSDKPlatformSubTypeQZone];

[shareParams SSDKSetupQQParamsByText:@"同城-專人-直送-4元起! 代取、代送、代買、代辦事,順風(fēng)件~? 微信公眾號(hào)-app均可下單" title:@"鄭州人都在用的跑腿APP" url:[NSURL URLWithString:userQRCodeString] thumbImage:[UIImage imageNamed:@"appIcon.png"] image:[UIImage imageNamed:@"appIcon.png"] type:SSDKContentTypeWebPage forPlatformSubType:SSDKPlatformSubTypeQQFriend];

[shareParams SSDKSetupWeChatParamsByText:@"同城-專人-直送-4元起! 代取、代送、代買、代辦事,順風(fēng)件~? 微信公眾號(hào)-app均可下單" title:@"鄭州人都在用的跑腿APP" url:[NSURL URLWithString:userQRCodeString] thumbImage:[UIImage imageNamed:@"appIcon.png"] image:[UIImage imageNamed:@"appIcon.png"] musicFileURL:nil extInfo:nil fileData:nil emoticonData:nil type:SSDKContentTypeWebPage forPlatformSubType:SSDKPlatformSubTypeWechatFav];

//[self startShareWithType:SSDKPlatformTypeSinaWeibo];

//[self startShareWithType:SSDKPlatformSubTypeWechatSession];

//[self startShareWithType:SSDKPlatformSubTypeWechatTimeline];

//[self startShareWithType:SSDKPlatformSubTypeQQFriend];

[shareParams SSDKSetupSinaWeiboShareParamsByText:@"同城-專人-直送-4元起! 代取、代送、代買、代辦事,順風(fēng)件~? 微信公眾號(hào)-app均可下單" title:@"鄭州人都在用的跑腿APP" image:[UIImage imageNamed:@"appIcon.png"] url:[NSURL URLWithString:userQRCodeString] latitude:0 longitude:0 objectID:nil type:SSDKContentTypeWebPage];

//2、分享(可以彈出我們的分享菜單和編輯界面)

[ShareSDK showShareActionSheet:nil //要顯示菜單的視圖, iPad版中此參數(shù)作為彈出菜單的參照視圖,只有傳這個(gè)才可以彈出我們的分享菜單,可以傳分享的按鈕對(duì)象或者自己創(chuàng)建小的view 對(duì)象,iPhone可以傳nil不會(huì)影響

items:@[@(SSDKPlatformTypeSinaWeibo),

@(SSDKPlatformSubTypeQZone),

//@(SSDKPlatformTypeSMS),

//@(SSDKPlatformTypeCopy),

//@(SSDKPlatformSubTypeWechatSession),

//@(SSDKPlatformSubTypeWechatTimeline),

@(SSDKPlatformSubTypeQQFriend),

@(SSDKPlatformSubTypeWechatFav)]

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;

}

}

];

}

[3]使用自定義UI界面實(shí)現(xiàn)代碼

其中shareType為平臺(tái)類型,UI自己實(shí)現(xiàn)。

[ShareSDK share:shareType parameters:publishContent onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {

switch (state) {

case SSDKResponseStateSuccess:

{

NSLog(@"分享成功!");

[self showAlertViewWithTitle:@"分享成功" message:nil];

break;

}

case SSDKResponseStateFail:

{

NSLog(@"分享失??!");

[self showAlertViewWithTitle:@"分享失敗" message:nil];

break;

}

case SSDKResponseStateCancel:

{

[self showAlertViewWithTitle:@"取消分享" message:nil];

break;

}

default:

break;

}

}];

3.適配iOS9+(官方文檔都有詳細(xì)信息)

大部分社交平臺(tái)接口不支持https協(xié)議

小部分社交平臺(tái)SDK不支持bitcode

添加白名單Schemes(在info.plist中設(shè)置)

添加URL types

URL Schemes內(nèi)容為:

各平臺(tái)縮寫+appID

其中QQ+appID的16進(jìn)制(必須是大寫字母,且不夠8為數(shù)的,前面添加0)

以上均為大概信息步驟,具體步驟以及代碼看官方文檔,官方還是寫的比較詳細(xì)。我這里只是用作自我總結(jié),加深記憶。

補(bǔ)充問題:

1.開發(fā)中使用shareSDk的UI界面,新浪微博不能直接跳轉(zhuǎn)app,先跳出shareSDK的彈窗,完善信息后才能跳轉(zhuǎn)。(shareSDK的彈窗的右邊圖片默認(rèn)是變型的,但是不影響分享后的圖片,介于美觀考慮,不推薦使用默認(rèn)分享UI)。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容