官網(wǎng): http://www.mob.com/#/
1 pod 導(dǎo)入
pod 導(dǎo)入 (最好加 版本號)
# 主模塊(必須)
pod 'ShareSDK3', '~> 3.1.4'
# UI模塊(非必須,需要用到ShareSDK提供的分享菜單欄和分享編輯頁面需要以下1行)
pod 'ShareSDK3/ShareSDKUI'
# 平臺SDK模塊(對照一下平臺,需要的加上。如果只需要QQ、微信、新浪微博,只需要以下3行)
pod 'ShareSDK3/ShareSDKPlatforms/QQ'
pod 'ShareSDK3/ShareSDKPlatforms/SinaWeibo'
pod 'ShareSDK3/ShareSDKPlatforms/WeChat'
pod 'ShareSDK3/ShareSDKPlatforms/GooglePlus'
pod 'ShareSDK3/ShareSDKPlatforms/RenRen'
pod 'ShareSDK3/ShareSDKPlatforms/AliPaySocial'
pod 'ShareSDK3/ShareSDKPlatforms/Kakao'
真機(jī) 修改
真機(jī) 修改
Build Active Architecture Only —— YES
Enable Bitcode NO
2 快速 集成
引入頭文件
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKConnector/ShareSDKConnector.h>
//騰訊開放平臺(對應(yīng)QQ和QQ空間)SDK頭文件
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>
//微信SDK頭文件
#import "WXApi.h"
//新浪微博SDK頭文件
#import "WeiboSDK.h"
//新浪微博SDK需要在項目Build Settings中的Other Linker Flags添加"-ObjC"
//人人SDK頭文件
#import <RennSDK/RennSDK.h>
//GooglePlus SDK頭文件
#import <GooglePlus/GooglePlus.h>
//GooglePlus SDK需要在項目Build Settings中的Other Linker Flags添加"-ObjC"
連接社交平臺
/**
* 設(shè)置ShareSDK的appKey,如果尚未在ShareSDK官網(wǎng)注冊過App,請移步到http://mob.com/login 登錄后臺進(jìn)行應(yīng)用注冊,
* 在將生成的AppKey傳入到此方法中。
* 方法中的第二個第三個參數(shù)為需要連接社交平臺SDK時觸發(fā),
* 在此事件中寫入連接代碼。第四個參數(shù)則為配置本地社交平臺時觸發(fā),根據(jù)返回的平臺類型來配置平臺信息。
* 如果您使用的時服務(wù)端托管平臺信息時,第二、四項參數(shù)可以傳入nil,第三項參數(shù)則根據(jù)服務(wù)端托管平臺來決定要連接的社交SDK。
*/
[ShareSDK registerApp:@"iosv1101"
// 分享的平臺選擇
activePlatforms:@[
@(SSDKPlatformTypeSinaWeibo),
@(SSDKPlatformTypeMail),
@(SSDKPlatformTypeSMS),
@(SSDKPlatformTypeCopy),
@(SSDKPlatformTypeWechat),
@(SSDKPlatformTypeQQ),
@(SSDKPlatformTypeRenren),
@(SSDKPlatformTypeGooglePlus)]
onImport:^(SSDKPlatformType platformType)
{
// 導(dǎo)入平臺文件
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;
case SSDKPlatformTypeGooglePlus:
[ShareSDKConnector connectGooglePlus:[GPPSignIn class]
shareClass:[GPPShare class]];
break;
default:
break;
}
}
onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
{
// 具體的設(shè)置
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"
authType:SSDKAuthTypeBoth];
break;
default:
break;
}
}];
3. SSO 免登錄 - 新注冊 微信 QQ 只能用這個。
添加Scheme白名單
info.plist中添加一個LSApplicationQueriesSchemes,類型為Array。
具體內(nèi)容 查看 ios9 必看。
快速 添加
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wechat</string>
<string>weixin</string>
<string>alipay</string>
<string>alipayshare</string>
<string>mqqapi</string>
<string>mqq</string>
<string>mqzone</string>
<string>mqqwpa</string>
<string>wtloginmqq2</string>
<string>mqqopensdkapiV3</string>
<string>mqqopensdkapiV2</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqzoneopensdkapiV2</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapi</string>
<string>mqzoneopensdk</string>
<string>sinaweibo</string>
<string>sinaweibohd</string>
<string>sinaweibosso</string>
<string>sinaweibohdsso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>
<string>TencentWeibo</string>
<string>tencentweiboSdkv2</string>
<string>yixin</string>
<string>yixinopenapi</string>
</array>
info - URL Types - 配置 SSO 信息
添加 Type
URL Schemes 添加 各個平臺 注冊的 APPID
新浪微博 wb + appid
微信 wx + appid
QQ QQ + appid (轉(zhuǎn)換 16進(jìn)制,8位)
注意:在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)換后的字母要大寫) 轉(zhuǎn)換16進(jìn)制的方法:echo ‘ibase=10;obase=16;801312852′ |bc,其中801312852為QQ的AppID
4. 默認(rèn) 分享視圖
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
- (void)share{
// /1、創(chuàng)建分享參數(shù)
NSArray* imageArray = @[[UIImage imageNamed:@"select_left"]];
// (注意:圖片必須要在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ù)作為彈出菜單的參照視圖,只有傳這個才可以彈出我們的分享菜單,可以傳分享的按鈕對象或者自己創(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;
}
}];
}
}
5. 自定義分享
直接分享,不編輯。
#import <ShareSDK/ShareSDK.h>
自己畫界面。調(diào)用方法
- (void)shareNode{
NSArray* imageArray = @[[UIImage imageNamed:@"test_share"]];
// (注意:圖片必須要在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:@"www.baidu.com"]
title:@"分享標(biāo)題"
type:SSDKContentTypeAuto];
// 選擇一個平臺
[ShareSDK share:SSDKPlatformTypeSinaWeibo
parameters:shareParams
onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { //。。。。處理回調(diào)}
}];
}
}