ShareSDK3 4.0.4

ShareSDK3 4.0.4

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2017年11月

[JinghuangLiu]anplex qc123456 维护。



ShareSDK3 4.0.4

  • Jinghuang Liu

ShareSDK

  • ShareSDK 是全球最受欢迎的应用和移动游戏社交 SDK!我们已支持超过 100,000 个客户。ShareSDK 可以轻松支持世界上的 40+ 个社交平台,用于第三方登录、分享和与朋友列表互动。只需几小时,这个小包就能让你的应用实现完全社交化!想要从你的应用中发布到中国社交平台?这可能是你的最佳选择!

内容

  • 入门
    • 功能
    • [分类结构【ShareSDK 分类结构】](#Category structure【ShareSDK Category structure】)
    • [如何轻松集成 ShareSDK](#How to integrate ShareSDK easily)
    • [选项配置](#Option Configuration)
  • 通用 API
  • 示例
  • 注意事项

功能

  • 分享到第三方 SNS 平台。
  • 第三方登录。

分类结构【ShareSDK Category structure】

ShareSDK 包含:

1、ShareSDK(ShareSDK 库),包含:

SDK
  | ----- Required
        | ----- MOBFoundation.framework:Basic Functions Framework。(necessary)
  | ----- ShareSDK 
        | ----- ShareSDK.framework:Core Framework。(necessary)
        | ----- Support
              | ----- Required
                   | ----- ShareSDK.bundle:ShareSDK Resources。(necessary)
                   | ----- ShareSDKConnector.framework:Acting framework for plug-ShareSDK frame and outer frame connection. When necessary, use a third-party SDK.(necessary)
              | ----- Third-party platform's SDK(Platform SDK does not require can be removable)
              | ----- PlatformConnector 
              | ----- Optional
              	    | ----- ShareSDKExtension.framework:ShareSDK framework for functional expansion plug. Currently the main provider of third-party platform login, onekey share, screenshots sharing, shake sharing and other related functions. We need to use the above functions necessary。
                    | ----- ShareSDKUI.bundle:Share menu bar and share editorial page Resources。(customize these UI can be removed directly)
                    | ----- ShareSDKUI.framework:Share menu bar and share editorial page。(customize these UI can be removed directly)
                    | ----- ShareSDKConfigFile.bundle
                    | ----- ShareSDKConfigFile.framework

2、Demo(它包含 Objective-C, swift 示例 Demo)

3、doc(包含 Objective-C, swift 版本集成文档和新增功能)

如何轻松集成 ShareSDK

步骤 1:将 ShareSDK 导入您的项目

  • cocoapods 导入:

    主模块(必需)

    pod 'ShareSDK3'

 #Mob Public Library(必需)。如果 SMSSDK iOS2.0:可以同时集成,请参阅此说明:http://bbs.mob.com/thread-20051-1-1.html
pod 'MOBFoundation'


UI module(Non-essential,Use ShareSDK's UI(Share menu bar and share editorial page) needs)
```objc
pod 'ShareSDK3/ShareSDKUI'
pod 'ShareSDK3/ShareSDKExtension'

SNSPlatform SDK 模块(非必需。如果想要分享到 QQ/Wechat/Sinaweibo,则只需以下三行)

pod 'ShareSDK3/ShareSDKPlatforms/QQ'
pod 'ShareSDK3/ShareSDKPlatforms/SinaWeibo'
pod 'ShareSDK3/ShareSDKPlatforms/WeChat'

pod 'ShareSDK3/ShareSDKPlatforms/RenRen'
pod 'ShareSDK3/ShareSDKPlatforms/AliPaySocial'
pod 'ShareSDK3/ShareSDKPlatforms/Kakao'
pod 'ShareSDK3/ShareSDKPlatforms/Yixin'
pod 'ShareSDK3/ShareSDKPlatforms/Facebook'
pod 'ShareSDK3/ShareSDKPlatforms/Copy'
pod 'ShareSDK3/ShareSDKPlatforms/Evernote'
pod 'ShareSDK3/ShareSDKPlatforms/GooglePlus'
pod 'ShareSDK3/ShareSDKPlatforms/Instagram'
pod 'ShareSDK3/ShareSDKPlatforms/Instapaper'
pod 'ShareSDK3/ShareSDKPlatforms/Line'
pod 'ShareSDK3/ShareSDKPlatforms/Mail'
pod 'ShareSDK3/ShareSDKPlatforms/SMS'
pod 'ShareSDK3/ShareSDKPlatforms/WhatsApp'
pod 'ShareSDK3/ShareSDKPlatforms/WeChat'
pod 'ShareSDK3/ShareSDKPlatforms/MeiPai'
pod 'ShareSDK3/ShareSDKPlatforms/YouTube'
pod 'ShareSDK3/ShareSDKPlatforms/Twitter'
pod 'ShareSDK3/ShareSDKPlatforms/DingTalk'
pod 'ShareSDK3/ShareSDKPlatforms/Dropbox'

 #using the configuration file sharing module (optional) 
pod 'ShareSDK3/ShareSDKConfigurationFile'
 
 #extension module (optional) 
pod 'ShareSDK3/ShareSDKExtension'

#ShareSDK currently supports a platform (SDK platform removal does not affect the sharing and authorization functions)
#platform statement replaces the ShareSDKPlatforms module statement can  
pod 'ShareSDK3/PlatformConnector/QQ'
pod 'ShareSDK3/PlatformConnector/SinaWeibo'
pod 'ShareSDK3/PlatformConnector/WeChat'
pod 'ShareSDK3/PlatformConnector/RenRen'
pod 'ShareSDK3/PlatformConnector/AliPaySocial'  
  • 手动导入:

    • 1、下载最新版本的 ShareSDK,并将其拖放到您的项目中

      (1)、下载最新版本的 ShareSDK,然后将获得以下文件。

      ![img](http://images2015.cnblogs.com/blog/708376/201512/708376-20151217215634646-932311230.png)
      

      (2)、选择 ShareSDK 文件并拖放到您的项目中(或只需按住键盘上的 Control 键,单击您的项目,即右键单击您的项目,然后选择“将文件添加到 …”)。
      然后您将看到一个如下窗口,勾选“如果需要,将项目将复制到目标组的文件夹中”并单击“完成”按钮。

      ![img](http://images2015.cnblogs.com/blog/708376/201512/708376-20151217214621381-255952184.png)
      

      (3)、现在您已将 ShareSDK 文件添加到项目中,它将看起来像这样

      ![img](http://images2015.cnblogs.com/blog/708376/201512/708376-20151217215149318-1957357410.png)
      
  • 2、添加必要的框架

必需框架:

libicucore.dylib
libz.dylib
libstdc++.dylib
JavaScriptCore.framework

可选框架:

necessary for the SSO Login of Sina weibo

ImageIO.framework
libsqlite3.dylib
necessary for the SSO Login of WeChat

libsqlite3.dylib
necessary for the SSO Login of QZone or QQ Friend share

libsqlite3.dylib
necessary for Mail or SMS

MessageUI.framework

添加框架的步骤

    ![img](http://www.mob.com/html/images/github/sharesdk-integrate-4.png)

步骤 2:导入头文件,注册 Appkey,并选择所需平台并初始化它们

1、登录到 http://reg.sharesdk.cn/ 注册成为 Mob 开发者,然后点击此处创建 Mob 应用程序,此时您将获取到 Appkey。

2、在 Info.plist 中设置 MOBAppKey 和 MOBAppSecret
(setappkey)

3、打开 AppDelegate.m 文件导入 .h 文件

4、对每个 SNS 的 Open Platform key 进行配置,参考:http://bbs.mob.com/forum.php?mod=viewthread&tid=275&page=1&extra=#pid860

#import <ShareSDK/ShareSDK.h>

//Links Native SDK use
#import <ShareSDKConnector/ShareSDKConnector.h>

#import <ShareSDKUI/ShareSDKUI.h>

//QQ SDK header file
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>

//Wechat SDK header file
#import "WXApi.h"

//SinaWeibo SDK header file
#import "WeiboSDK.h"

并将初始化代码添加到 -(BOOL)application: didFinishLaunchingWithOptions: 方法中

-   (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions 
{     
     [ShareSDK registerActivePlatforms:@[
                            @(SSDKPlatformTypeSinaWeibo),
                            @(SSDKPlatformTypeMail),
                            @(SSDKPlatformTypeSMS),
                            @(SSDKPlatformTypeCopy),
                            @(SSDKPlatformTypeWechat),
                            @(SSDKPlatformTypeQQ),
                            @(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;
                  default:
                    break;
                }
          }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) 
          {
                switch (platformType)
                {
                  case SSDKPlatformTypeSinaWeibo:
                      //设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
                      [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 SSDKPlatformTypeGooglePlus:
                      [appInfo SSDKSetupGooglePlusByClientID:@"232554794995.apps.googleusercontent.com"
                                                clientSecret:@"PEdFgtrMw97aCvf0joQj7EMk"
                                                 redirectUri:@"https://"];
                    break;
                   default:
                    break;
              }
          }];
 return YES;
}

步骤 3:构造分享内容和分享

1、创建分享参数。请参阅 ShareSDK.framework 中的 ShareSDK.h 或 Demo 了解具体用法。

2、要显示分享内容视图,您需要调用 showShareActionSheet… 方法。

    //1、Create Share parameters
    NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];
    if (imageArray) {
 
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        [shareParams SSDKSetupShareParamsByText:@"Share Content"
                                         images:imageArray
                                            url:[NSURL URLWithString:@"http://mob.com"]
                                          title:@"ShareTitle"
                                           type:SSDKContentTypeAuto];
        //2、To show the share content view
        [ShareSDK showShareActionSheet:nil //The way to share content for iPad : we recommend you to use a child view of ViewController as the "anchor" to be the container. It can be an button、custom view etc. Only in this way do the share view and authorization view display correctly. 
                                 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:@"Share Success!"
                                                                                   message:nil
                                                                                  delegate:nil
                                                                         cancelButtonTitle:@"OK"
                                                                         otherButtonTitles:nil];
                               [alertView show];
                               break;
                           }
                           case SSDKResponseStateFail:
                           {
                               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Share Fail"
                                                                                   message:[NSString stringWithFormat:@"%@",error]
                                                                                  delegate:nil
                                                                         cancelButtonTitle:@"OK"
                                                                         otherButtonTitles:nil, nil];
                                [alert show];
                                break;
                               }
                            default:
                               break;
                       }
 
                   }];

恭喜!您成功了,结果可能如下截图所示。
(ShareSDK提供的UI界面分享)

选项配置

选项 1:集成 QQ 的特定方式

1、登录到 Open QQ 平台 (http://open.qq.com/)to 成为开发者并创建应用程序以获取应用的 AppID。

2、返回您的项目,选择 -Info.plist (- 代表您的项目名称) 文件。为 key 添加 URL Scheme,值的格式为:"QQ" + AppID 的十六进制数(如果十六进制数的长度小于 8,则用零填充以确保长度为 8)。以下是一个示例,如果您的 AppID 的十六进制数是 5FB8B52,则 URL Scheme 的最终值是 QQ05FB8B52。

(QQ url schemes)

3、打开 -AppDelegate.m (- 代表您的项目名称),导入 QQSDK 头文件

#import <TencentOpenAPI/QQApiInterface.h> 
#import <TencentOpenAPI/TencentOAuth.h>

4、在 -(BOOL)application: didFinishLaunchingWithOptions: 方法中添加代码

-   (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
//...        
//Initialize QQ Platform  
[ShareSDK registerApp:@"********"  // *** is the AppKey that you just got 
          activePlatforms:@[@(SSDKPlatformTypeQQ)]
          onImport:^(SSDKPlatformType platformType) {
               switch (platformType)
               {  
                  case SSDKPlatformTypeQQ:
                  // link to Native QQSDK
                  [ShareSDKConnector connectQQ:[QQApiInterface class]
                                    tencentOAuthClass:[TencentOAuth class]];
                  break;
                  default:
                      break;
               }
          }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) { 
               switch (platformType)
               {
                  case SSDKPlatformTypeQQ:
                  //The parameter “100371282” is the AppID of QQ App   
                  [appInfo SSDKSetupQQByAppId:@"100371282"
                                       appKey:@"aed9b0303e3ed1e27bae87c33761161d"
                                     authType:SSDKAuthTypeBoth];
                  break;
                  default:
                      break;
               }
          }];

      //... 
}

选项 2:集成 Wechat 的特定方式

1、登录到 WeChat 开放平台 (http://open.weixin.qq.com/) 成为 WeChat 开发者并创建应用程序以获取应用的有效 AppID 和 AppSecret。

2、回到您的项目,选择 -Info.plist (- 代表您的项目名称) 文件。为 key 添加 WeChat URL Scheme,值是 WeChat AppID(例如:wx4868b35061f87885)。以下是一个示例

(Wechat url schemes)

3、打开 -AppDelegate.m (- 代表您的项目名称),导入 WechatSDK 头文件

#import "WXApi.h"

4、在 -(BOOL)application: didFinishLaunchingWithOptions: 方法中添加代码

-   (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
//...        
//Initialize wechat Platform  
[ShareSDK registerApp:@"********"  // *** is the AppKey that you just got 
          activePlatforms:@[@(SSDKPlatformTypeWechat)]
          onImport:^(SSDKPlatformType platformType) {
               switch (platformType)
               {  
                  case SSDKPlatformTypeWechat:
                  // link to Native WechatSDK
                   [ShareSDKConnector connectWeChat:[WXApi class] delegate:self];
                  break;
                  default:
                      break;
               }
          }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) { 
               switch (platformType)
               {
                  case SSDKPlatformTypeWechat:
                       //The parameter “wx6dd7a9b94f3dd72a” is the AppID of WeChat App     
                       [appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"
                                             appSecret:@"64020361b8ec4c99936c0e3999a9f249"];
                  break;
                  default:
                      break;
               }
          }];

      //... 
}

选项 3:集成 Google+ 的特定方式

1、登录到 Google+ 开发者平台成为开发者 (https://console.developers.google.com/home/) 并创建应用程序以获取应用的 ClientID。

2、返回您的项目,选择 -Info.plist (- 代表您的项目名称) 文件。为 key 添加 Google+ URL Scheme 和 URL identifier,值都是 BundleID(例如 cn.appgo.sharebyone),并且必须与 Google+ 仪表板的设置相同。以下是步骤

(Google+ url schemes)

3、在 -(BOOL)application: didFinishLaunchingWithOptions: 方法中添加代码

-   (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
//...        
//Initialize wechat Platform  
[ShareSDK registerApp:@"********"  // *** is the AppKey that you just got 
          activePlatforms:@[@(SSDKPlatformTypeGooglePlus)]
          onImport:^(SSDKPlatformType platformType) {
               switch (platformType)
               {  
                  //link to navite Google+ SDK
                   case SSDKPlatformTypeGooglePlus:
                        [ShareSDKConnector connectGooglePlus:[GPPSignIn class]
                                                  shareClass:[GPPShare class]];
                   break;
                   default:
                      break;
               }
          }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) { 
               switch (platformType)
               {
                  case SSDKPlatformTypeGooglePlus:
                       [appInfo SSDKSetupGooglePlusByClientID:@"***********" // Google+ clientID
                                                 clientSecret:@""
                                                  redirectUri:@""];
                  break;
                  default:
                      break;
               }
          }];

      //... 
}

ShareSDK.h

/**
 *  ShareSDK APIs
 */
@interface ShareSDK : NSObject

#pragma mark - initialization

/**
 *  Initialization ShareSDK
 *
 *  @param appKey                   ShareSDK Application ID,Log in to http://reg.sharesdk.cn/ to register to be a Mob developer , and click here to create a Mob application, then you will get the Appkey.
 *  @param activePlatforms          Sharing platform used collection,eg:@[@(SSDKPlatformTypeSinaWeibo),@(SSDKPlatformTypeTencentWeibo)];
 *  @param connectHandler           导入回调处理,当某个平台的功能需要依赖原平台提供的SDK支持时,需要在此方法中对原平台SDK进行导入操作。具体的导入方式可以参考ShareSDKConnector.framework中所提供的方法。
 *  @param configurationHandler     配置回调处理,在此方法中根据设置的platformType来填充应用配置信息
 */
+ (void)registerApp:(NSString *)appKey
    activePlatforms:(NSArray *)activePlatforms
           onImport:(SSDKImportHandler)importHandler
    onConfiguration:(SSDKConfigurationHandler)configurationHandler;

#pragma mark - authorize

/**
 *  authorize
 *
 *  @param platformType       
 *  @param @param settings    授权设置,目前只接受SSDKAuthSettingKeyScopes属性设置,如:@{SSDKAuthSettingKeyScopes : @[@"all", @"mail"]}
 *  @param stateChangeHandler 
 */
+ (void)authorize:(SSDKPlatformType)platformType
         settings:(NSDictionary *)settings
   onStateChanged:(SSDKAuthorizeStateChangedHandler)stateChangedHandler;

/**
 *  judgment weather to authorize
 *
 *  @param platformType 
 *  @return YES :has Authorized,NO : Not Authorized
 */
+ (BOOL)hasAuthorized:(SSDKPlatformType)platformTypem;

/**
 *  cancelAuthorize
 *
 *  @param platformType  
 */
+ (void)cancelAuthorize:(SSDKPlatformType)platformType;

#pragma mark - User

/**
 *  Get User Info
 *
 *  @param platformType    
 *  @param stateChangeHandler 
 */
+ (void)getUserInfo:(SSDKPlatformType)platformType
     onStateChanged:(SSDKGetUserStateChangedHandler)stateChangedHandler;
     
/**
 *  Share Content
 *
 *  @param platformType             
 *  @param parameters               
 *  @param stateChangeHandler       
 */
+ (void)share:(SSDKPlatformType)platformType
   parameters:(NSMutableDictionary *)parameters
onStateChanged:(SSDKShareStateChangedHandler)stateChangedHandler;

简单分享

#import <ShareSDK/ShareSDK.h>
//...
[shareParams SSDKSetupShareParamsByText:@"Share Content"
                                 images:imageArray
                                    url:[NSURL URLWithString:@"http://mob.com"]
                                  title:@"Share title" 
                                   type:SSDKContentTypeImage];
[ShareSDK share:SSDKPlatformTypeSinaWeibo
             parameters:shareParams
         onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {//...}

(simplyShare url schemes)

显示分享编辑器

#import <ShareSDK/ShareSDK.h>
//...
[shareParams SSDKSetupShareParamsByText:@"Share Content"
                                 images:imageArray
                                    url:[NSURL URLWithString:@"http://mob.com"]
                                  title:@"Share title" 
                                   type:SSDKContentTypeImage];
[ShareSDK showShareEditor:SSDKPlatformTypeSinaWeibo
               otherPlatformTypes:nil
                      shareParams:shareParams
              onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {//...}

(EditorShare url schemes)