帮助与文档

> >

一、 集成前准备工作

1. 注册应用获取appkey:参考链接

2. 下载SDK:链接

SDK目录结构说明:

目录结构

 

SDK:
   Required:
      MOBFoundation.framework (基础工具库)
   ShareSDK:
      ShareSDK.framework (主业务实现)
      Support:
          Required:
              ShareSDK.bundle (ShareSDK资源文件)
              ShareSDKConnector.framework(v4.2.0版本后已废弃)
              PlatformConnector: 
                  ... (各个平台独立逻辑依赖库,只需要集成需要的平台即可)
              PlatformSDK:
                  ... (各个平台的SDK文件,不集成默认走去SDK业务逻辑,目前支持大部分主流平台,如QQ 微博 微信等)
              Optional:(可选)
                  ShareSDKUI.bundle (分享UI的资源文件)
                  ShareSDKUI.framework (分享UI库)
                  ShareSDKConfigFile.framework(xml配置文件形式分享依赖库)
                  ShareSDKConfigFile.bundle (xml配置文件形式分享资源文件)
                  ShareSDKExtension.framework(功能的扩展框架插件。(第三方平台检测、 一键分享、截屏分享、摇一摇分享等相关功能)

 

二、快速集成

1. 将下载的SDK解压后导入到您的工程中:

未命名

2. 添加依赖库 添加步骤见下图

233D16A0-E241-4D4B-ACF2-4C03259F995A

  • 必要依赖库:
libc++.tbd
libz.tbd
libsqlite3.tbd
  • 社交平台依赖库:

    新浪微博

ImageIO.framework
Photos.framework

    Instagram

AssetsLibrary.framework
Photos.framework

    美拍

AssetsLibrary.framework

3. 设置ShareSDK的appkey

在项目工程的Info.plist 中如图增加 MOBAppKey 和 MOBAppSecret 两个字段

appkey
友情提示:如果您同时多个MOBSDK产品 在info.plist中的设置一次就可以了。

4. 配置xcode项目

  • Build Settings中的Other Linker Flags添加”-ObjC”

8

  • 微博平台还需要配置下ATS

具体方法:

在项目的info.plist中添加一个Key:App Transport Security  Settings,类型为字典类型。

然后给它添加一个Key:Allow Arbitrary Loads,类型为Boolean类型,值为YES;

A4FACB65-2EED-437F-8D8B-6378D093AAC6

  • 配置URL Scheme

url

 

  • 各平台URL Scheme配置参考:
平台 配置URL Scheme 格式 举例 备注
新浪微博 wb+微博appKey 如AppKey:568898243 wb568898243
QQ/Qzone "tencent"+腾讯QQ开放平台appID 如appID:100371282 tencent100371282
腾讯微博 只能网页授权登录,无URL Scheme配置
微信 微信的appid wx4868b35061f87885
Facebook fb+在facebook注册得到的ApiKey 如ApiKey:107704292745179 fb107704292745179
Twitter twitterkit-在twitter注册得到的ConsumerKey 如ConsumerKey:viOnkeLpHBKs6KXV7MPpeGyzE twitterkit-viOnkeLpHBKs6KXV7MPpeGyzE
易信 易信appkey yx0d9a9f9088ea44d78680f3274da1765f
Google 只能网页授权登录,无URL Scheme的配置
领英 只能网页授权登录,无URL Scheme的配置
人人网 rm+人人网appid+Bundle id 如appid:226427 Bundle id:com.mob.demoShareSDK rm226427com.mob.demoShareSDK 在人人网注册应用的Bundle id一定要和自己项目里的Bundle id一致
豆瓣 只能网页授权登录,无URL Scheme配置
开心网 只能网页授权登录,无URL Scheme配置
Pocket Pocket的回调地址 如:pocketapp1234 pocketapp1234
Instagram 只能网页授权登录,无URL Scheme配置
Tumblr tb+ConsumerKey 如:2QUXqO9fcgGdtGG1FcvML6ZunIQzAEL8xY6hIaxdJnDti2DYwM tb2QUXqO9fcgGdtGG1FcvML6ZunIQzAEL8xY6hIaxdJnDti2DYwM Tumblr必须要配置这个URL Scheme,才可以跳授权登录界面,主要是跳Safari浏览器授权网页授权登录
Flickr 只能网页授权登录,无URL Scheme配置
YouDaoNote 只能网页授权登录,无URL Scheme配置
印象笔记 只能网页授权登录,无URL Scheme配置
Kakao kakao+appkey 如apply:48d3f524e4a636b08d81b3ceb50f1003 kakao48d3f524e4a636b08d81b3ceb50f1003
Pinterest pdk+ClientId 如ClientId:4797078908495202393 pdk4797078908495202393
Dropbox 只能网页授权登录,无URL Scheme配置
VKontakte vk+appid 如appid:5312801 vk5312801
明道 只能网页授权登录,无URL Scheme配置
Instapaper 只能网页授权登录,无URL Scheme配置
YouTube 只能网页授权登录,无URL Scheme配置
Line line3rdp+Bundle id 可以直接固定line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)这样配置,$(PRODUCT_BUNDLE_IDENTIFIER)自动
显示您自己的项目里的Bundle id
中国移动CMCC 需要在真机上测试,并且安装SIM卡
天翼 只能网页授权登录,无URL Scheme配置
FacebookAccount 需要配置FacebookAppID:APPID,AccountKitClientToken:token,URL Scheme:ak+appid 例如token:c30c08723aa8c48fbd5e01d1c3103891,APPID:1412473428822331,URL Scheme配置为:ak1412473428822331
Telegram 只能网页授权登录,无URL Scheme配置
Reddit 只能网页授权登录,无URL Scheme配置
抖音 抖音初始化的appkey aw9ivykfjvi4hpwo
企业微信 企业微信初始化的appkey wwautha21eaecf93f0e3ba000012

特殊:QQ分享需要另配置URL Scheme:

在URL Types中添加QQ的AppID,其格式为:”QQ” + AppId的16进制(如果appId转换的16进制数不够8位则在前面补0,如转换的是:5FB8B52,则最终填入为:QQ05FB8B52 注意:转换后的字母要大写) 转换16进制的方法:echo ‘ibase=10;obase=16;801312852’ |bc,其中801312852为QQ的AppID,见下图

9406F13D-F78B-4261-A52B-CFBC7ECF4890

 

  • 配置白名单

1. 在项目的info.plist中添加key:LSApplicationQueriesSchemes,类型为Array

2. 然后给它添加一个需要支持的项目,类型为字符串类型:

FBEF076A-611A-4B43-B8A9-F1825CC08FDA

各平台OpenURL白名单说明

新浪微博

  • sinaweibo,
  • sinaweibohd,
  • sinaweibosso,
  • sinaweibohdsso,
  • weibosdk,
  • weibosdk2.5
  • [后两个若导入新浪SDK则需要]

腾讯微博

  • TencentWeibo,
  • tencentweiboSdkv2
  • [控制台会提示这两个,但是腾讯微博SDK已经弃用,可以忽略不配置]

豆瓣

  • 无需配置

开心网

  • 无需配置

微信

  • wechat
  • weixin

企业微信

  • wxwork
  • wxworkrdm

FacebookMessenger

  • fb-messenger
  • fb-messenger-platform-20150714

易信

  • yixin,
  • yixinopenapi
  • yixinoauth
  • yixinfav

支付宝

  • alipay,
  • alipayshare

QQ

  • mqqOpensdkSSoLogin,
  • mqqopensdkapiV2,
  • mqqopensdkapiV3,
  • wtloginmqq2,
  • mqq,
  • mqqapi
  • timapi

QZONE

  • mqzoneopensdk,
  • mqzoneopensdkapi,
  • mqzoneopensdkapi19,
  • mqzoneopensdkapiV2,
  • mqqOpensdkSSoLogin,
  • mqqopensdkapiV2,
  • mqqopensdkapiV3,
  • wtloginmqq2,
  • mqqapi,
  • mqqwpa
  • mqzone,
  • mqq
  • mqqopensdkapiV4

[:若同时使用QQQZONE,则直接添加本格即可]

TIM

  • mqq
  • mqqapi
  • mqqwpa
  • mqqbrowser
  • mttbrowser
  • mqqOpensdkSSoLogin
  • mqqopensdkapiV2
  • mqqopensdkapiV3
  • mqqopensdkapiV4
  • wtloginmqq2
  • mqzone
  • mqzoneopensdk
  • mqzoneopensdkapi
  • mqzoneopensdkapi19
  • mqzoneopensdkapiV2
  • mqqapiwallet
  • mqqopensdkfriend
  • mqqopensdkdataline
  • mqqgamebindinggroup
  • mqqopensdkgrouptribeshare
  • tencentapi.qq.reqContent
  • tencentapi.qzone.reqContent
  • tim
  • timapi
  • timopensdkfriend
  • timwpa
  • timgamebindinggroup
  • timapiwallet
  • timOpensdkSSoLogin
  • timopensdkgrouptribeshare
  • wtlogintim
  • timopensdkapiV4
  • timgamebindinggroup
  • timopensdkdataline
  • wtlogintimV1
  • timapiV1

人人网

  • renrenapi,
  • renrenios,
  • renreniphone,
  • renren,
  • 以及在使用人人SDK时所需配置的URL Scheme,例如:rm226427com.mob.demoShareSDK

Facebook

  • fbauth2
  • fbauth
  • fbapi20130214
  • fbapi

Twitter

  • twitterauth

Telegram

  • telegram
  • tg

Pocket

  • pocket-oauth-v1

Pinterest

  • pinit
  • pinterestsdk.v1

Instagram

  • instagram

VKontakte

  • vkauthorize

WhatsApp

  • whatsapp

Line

  • line
  • lineauth
  • line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)

KakaoTalk

  • kakaolink

KaokaoStory

  • storylink
  • kakaokompassauth
  • storykompassauth
  • kakao+appid 例kakao48d3f524e4a636b08d81b3ceb50f1003

LinkedIn

  • 无需配置

Tumblr

  • 无需配置

非平台类,如短信,复制,邮件等

  • 无需配置

钉钉

  • dingtalk
  • dingtalk-open

美拍

  • mtmv
  • mpsharesdk10
  • mpsharesdk11

YouTube

  • youtube

抖音

  • douyinsharesdk
  • douyinopensdk
必看注意:
1.iOS9中,如果没有添加上述白名单,系统会打印类似如下提示:.-canOpenURL: failed for URL: "sinaweibohdsso://xxx" - error: "This app is not allowed to query for scheme sinaweibohdsso”(如下图)如没有添加相关白名单,有可能导致分享失败,例如不会跳转微信,不会跳转QQ
2.添加完上述所需的名单,系统依然会打印类似信息:.-canOpenURL: failed for URL: "sinaweibohdsso://xxx" - error: “null”这是系统打印的信息,目前是无法阻止其打印,即无法消除的
3.上述白名单,是技术人员通过不断的测试收集整理所得,如果各位开发者朋友发现上表格有所遗漏,请根据系统信息添加相关白名单即可。

5. 添加实现代码

 

1. 导入头文件并初始化注册第三方平台

通常都是在启动的时候在 application:didFinishLaunchingWithOptions:中添加初始化方法,也可保证注册在sharesdk的业务执行之前即可(各社交平台申请AppKey的网址及申请流程汇总

#import <ShareSDK/ShareSDK.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
//QQ
[platformsRegister setupQQWithAppId:@"100371282" appkey:@"aed9b0303e3ed1e27bae87c33761161d"];

//微信
[platformsRegister setupWeChatWithAppId:@"wx617c77c82218ea2c" appSecret:@"c7253e5289986cf4c4c74d1ccc185fb1"];

//新浪
[platformsRegister setupSinaWeiboWithAppkey:@"568898243" appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3" redirectUrl:@"http://www.sharesdk.cn"];

//Facebook
[platformsRegister setupFacebookWithAppkey:@"1412473428822331" appSecret:@"a42f4f3f867dc947b9ed6020c2e93558" displayName:@"shareSDK"];

//Twitter
[platformsRegister setupTwitterWithKey:@"viOnkeLpHBKs6KXV7MPpeGyzE" secret:@"NJEglQUy2rqZ9Io9FcAU9p17omFqbORknUpRrCDOK46aAbIiey" redirectUrl:@"http://mob.com"];
//Instagram
[platformsRegister setupInstagramWithClientId:@"ff68e3216b4f4f989121aa1c2962d058" clientSecret:@"1b2e82f110264869b3505c3fe34e31a1" redirectUrl:@"http://sharesdk.cn"];

//钉钉
[platformsRegister setupDingTalkWithAppId:@"dingoabcwtuab76wy0kyzo"];

//支付宝
[platformsRegister setupAliSocialWithAppId:@"2017062107540437"];

//豆瓣
[platformsRegister setupDouBanWithApikey:@"02e2cbe5ca06de5908a863b15e149b0b" appSecret:@"9f1e7b4f71304f2f" redirectUrl:@"http://www.sharesdk.cn"];

//Dropbox
[platformsRegister setupDropboxWithAppKey:@"us514wslpfojbxc" appSecret:@"w0nmp4os3ngo1ja" redirectUrl:@"http://localhost"];

//易信
[platformsRegister setupYiXinByAppId:@"yx0d9a9f9088ea44d78680f3274da1765f" appSecret:@"1a5bd421ae089c3" redirectUrl:@"https://open.yixin.im/resource/oauth2_callback.html"];
//Flickr
[platformsRegister setupFlickrWithApiKey:@"cbed81d4a1bc7417693ab7865e354717" apiSecret:@"4c490343869091f2"];

//Instapaper
[platformsRegister setupInstapaperWithConsumerKey:@"4rDJORmcOcSAZL1YpqGHRI605xUvrLbOhkJ07yO0wWrYrc61FA" consumerSecret:@"GNr1GespOQbrm8nvd7rlUsyRQsIo3boIbMguAl9gfpdL0aKZWe"];

//Line
[platformsRegister setupLineAuthType:SSDKAuthorizeTypeBoth];

//YinXiang
[platformsRegister setupEvernoteByConsumerKey:@"46131514-6903" consumerSecret:@"08d7a6f3afcc888a" sandbox:YES];

//Evernote
[platformsRegister setupEvernoteByConsumerKey:@"46131514-6903" consumerSecret:@"08d7a6f3afcc888a" sandbox:YES];

//kakao
[platformsRegister setupKaKaoWithAppkey:@"9c17eb03317e0e627ec95a400f5785fb" restApiKey:@"802e551a5048c3172fc1dedaaf40fcf1" redirectUrl:@"http://www.mob.com/oauth"];

//VKontakte
[platformsRegister setupVKontakteWithApplicationId:@"5312801" secretKey:@"ZHG2wGymmNUCRLG2r6CY" authType:SSDKAuthorizeTypeBoth];

//YouTube
[platformsRegister setupYouTubeWithClientId:@"906418427202-jinnbqal1niq4s8isbg2ofsqc5ddkcgr.apps.googleusercontent.com" clientSecret:@"" redirectUrl:@"http://localhost"];

//美拍
[platformsRegister setupMeiPaiWithAppkey:@"1089867639"];

//腾讯微博
[platformsRegister setupTencentWeiboWithAppkey:@"801307650" appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c" redirectUrl:@"http://www.sharesdk.cn"];

//人人网
[platformsRegister setupRenRenWithAppId:@"226427" appKey:@"fc5b8aed373c4c27a05b712acba0f8c3" secretKey:@"f29df781abdd4f49beca5a2194676ca4" authType:SSDKAuthorizeTypeBoth];

//CMCC
[platformsRegister setupCMCCByAppId:@"300011862498" appKey:@"38D9CA1CC280C5F207E2C343745D4A4B" displayUI:YES];

//有道云笔记
[platformsRegister setupYouDaoNoteWithConsumerKey:@"dcde25dca105bcc36884ed4534dab940" consumerSecret:@"d98217b4020e7f1874263795f44838fe" oauthCallback:@"http://www.sharesdk.cn/"];

//明道
[platformsRegister setupMingDaoByAppKey:@"97230F25CA5C" appSecret:@"A5DC29AF7C5A5851F28E903AE9EAC0" redirectUrl:@"http://mob.com"];

//开心网
[platformsRegister setupKaiXinByApiKey:@"358443394194887cee81ff5890870c7c" secretKey:@"da32179d859c016169f66d90b6db2a23" redirectUrl:@"http://www.sharesdk.cn/"];

//Google+
[platformsRegister setupGooglePlusByClientID:@"351114257251-isfr7cnt5gop930krntpf246d9ofv8j5.apps.googleusercontent.com" clientSecret:@"" redirectUrl:@"http://localhost"];

//Pinterest
[platformsRegister setupPinterestByClientId:@"4987008320438021391"];

//Pocket
[platformsRegister setupPocketWithConsumerKey:@"11496-de7c8c5eb25b2c9fcdc2b627" redirectUrl:@"pocketapp1234"];

//LinkedIn
[platformsRegister setupLinkedInByApiKey:@"46kic3zr7s4n" secretKey:@"RWw6WRl9YJOcdWsj" redirectUrl:@"http://baidu.com"];

//Instapaper
[platformsRegister setupInstapaperWithConsumerKey:@"4rDJORmcOcSAZL1YpqGHRI605xUvrLbOhkJ07yO0wWrYrc61FA" consumerSecret:@"GNr1GespOQbrm8nvd7rlUsyRQsIo3boIbMguAl9gfpdL0aKZWe"];

//Tumblr
[platformsRegister setupTumblrByConsumerKey:@"2QUXqO9fcgGdtGG1FcvML6ZunIQzAEL8xY6hIaxdJnDti2DYwM" consumerSecret:@"3Rt0sPFj7u2g39mEVB3IBpOzKnM3JnTtxX2bao2JKk4VV1gtNo" redirectUrl:@"http://sharesdk.cn"];

//SMS
[platformsRegister setupSMSOpenCountryList:NO];

//Telegram
[platformsRegister setupTelegramByBotToken:@"600852601:AAElp9J93JiYevLocDIEYPhEYulnMFuB_nQ" botDomain:@"http://127.0.0.1"];

//Reddit
[platformsRegister setupRedditByAppKey:@"ObzXn50T7Cg0Xw" redirectUri:@"https://www.mob.com/reddit_callback"];
//抖音
[platformsRegister setupDouyinByAppKey:@"aw9ivykfjvi4hpwo" appSecret:@"42b4caa6bda60bd49f05f06d0a4956e1"];
}];
}

 

2. 调用构造分享参数接口和分享的接口

  • 分享(无UI,不会弹出我们的分享菜单,直接分享)
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    [params SSDKSetupShareParamsByText:@"test" images:[UIImage imageNamed:@"shareImg.png"] url:[NSURL URLWithString:@"http://www.mob.com/"] title:@"title" type:SSDKContentTypeAuto];
    
    [ShareSDK share:SSDKPlatformTypeWechat parameters:params onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
        
        switch (state) {
            case SSDKResponseStateUpload:
                // 分享视频的时候上传回调,进度信息在 userData
                break;
            case SSDKResponseStateSuccess:
                //成功
                break;
            case SSDKResponseStateFail:
           {
             NSLog(@"--%@",error.description);
                //失败
                break;
           }
            case SSDKResponseStateCancel:
                //取消
                break;
                
            default:
                break;
        }
    }];
  • 授权 (每次都会重新向第三方平台请求授权)
    [ShareSDK authorize:SSDKPlatformTypeWechat settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
        
        switch (state) {
            case SSDKResponseStateSuccess:
                NSLog(@"%@",user.dictionaryValue);
                break;
            case SSDKResponseStateFail:
              {
             NSLog(@"--%@",error.description);
                //失败
                break;
           }
            case SSDKResponseStateCancel:
                //用户取消授权
                break;
                
            default:
                break;
        }
    }];
  • 获取用户信息
    [ShareSDK getUserInfo:SSDKPlatformTypeWechat onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
        
        switch (state) {
            case SSDKResponseStateSuccess:
                NSLog(@"%@",user.dictionaryValue);
                break;
            case SSDKResponseStateFail:
               {
             NSLog(@"--%@",error.description);
                //失败
                break;
           }
            case SSDKResponseStateCancel:
                //用户取消授权
                break;
                
            default:
                break;
    }];
  • 分享菜单(有UI,会弹出我们的菜单界面)
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    NSArray* imageArray = @[[[NSBundle mainBundle] pathForResource:@"D45" ofType:@"jpg"]];
    [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                     images:imageArray
                                        url:[NSURL URLWithString:@"https://www.mob.com"]
                                      title:@"分享标题"
                                       type:SSDKContentTypeAuto];
    
    //SSUIPlatformItem *item_1 = [[SSUIPlatformItem alloc] init];
    //item_1.platformName = @"item_1";
    //item_1.iconNormal = [UIImage imageNamed:@"COD13.jpg"];
    //item_1.iconSimple = [UIImage imageNamed:@"D11.jpg"];
    //item_1.platformId = @"123456789";
    //[item_1 addTarget:self action:@selector(test_1:)];
    
    //NSArray *items = nil;
    //    items = @[
    //              @(SSDKPlatformTypeQQ),
    //              @(SSDKPlatformTypeWechat),
    //              item_1,
    //              @(SSDKPlatformTypeSinaWeibo),
    //              @(SSDKPlatformTypeSMS),
    //              @(SSDKPlatformTypeMail),
    //              @(SSDKPlatformTypeCopy)
    //              ];
    //SSUIShareSheetConfiguration *config = [[SSUIShareSheetConfiguration alloc] init];
    //    config.style = SSUIActionSheetStyleSimple;
//    config.menuBackgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5];
    [ShareSDK showShareActionSheet:nil
                       customItems:items
                       shareParams:shareParams
                sheetConfiguration:nil
                    onStateChanged:^(SSDKResponseState state,
                                     SSDKPlatformType platformType,
                                     NSDictionary *userData,
                                     SSDKContentEntity *contentEntity,
                                     NSError *error,
                                     BOOL end)
     {
         
         switch (state) {
             
             case SSDKResponseStateSuccess:
                 break;
             case SSDKResponseStateFail:
                  {
             NSLog(@"--%@",error.description);
                //失败
                break;
           }
             case SSDKResponseStateCancel:
                 break;
             default:
             break;
         }
     }];
  • 分享之前弹出编辑界面
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
 [ShareSDK showShareEditor:SSDKPlatformTypeWechat
               otherPlatforms:nil
                  shareParams:params
          editorConfiguration:nil
               onStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                   
                   switch (state) {
                       case SSDKResponseStateUpload:
                           // 分享视频的时候上传回调,进度信息在 userData
                           break;
                       case SSDKResponseStateSuccess:
                           //成功
                           break;
                       case SSDKResponseStateFail:
                            {
                          NSLog(@"--%@",error.description);
                     //失败
                          break;
                        }
                       case SSDKResponseStateCancel:
                           //取消
                           break;
                           
                       default:
                           break;
                   }
                   
               }];

 

 

 

 

相关文档