mob_sharesdk 4.4.26

mob_sharesdk 4.4.26

Mober 维护。



  • 作者:
  • mob

ShareSDK

  • ShareSDK是全球最受欢迎的应用程序和移动游戏的社交SDK!我们已经支持超过10万客户,现在可以轻松支持40多个全球社交平台进行第三方登录、分享和与好友列表互动。只需几个小时,这个小巧的包就能让您的应用实现完全社交化!想在应用中发布中国的社交平台内容?这将可能是您最好的选择!

内容

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

特性

  • 分享到第三方社交媒体平台。
  • 第三方登录。

分类结构【ShareSDK 分类结构】

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 'mob_sharesdk'

 #Mob 公共库(必需)如果 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 'mob_sharesdk/ShareSDKUI'
pod 'ShareSDK3/ShareSDKExtension'

SNSPlatform SDK 模块(非必需。如果您想分享到 QQ/微信/Sinaweibo,只需以下三条命令)

pod 'mob_sharesdk/ShareSDKPlatforms/QQ'
pod 'mob_sharesdk/ShareSDKPlatforms/SinaWeibo'
pod 'mob_sharesdk/ShareSDKPlatforms/WeChat'   //(微信sdk不带支付的命令)
# pod 'mob_sharesdk/ShareSDKPlatforms/WeChatFull' //(微信sdk带支付的命令,和上面不带支付的不能共存,只能选择一个)

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

 #using the configuration file sharing module (optional) 
 pod 'mob_sharesdk/ShareSDKConfigurationFile'
 
 #extension module (optional) 
pod 'mob_sharesdk/ShareSDKExtension'
  • 手动导入:

    • 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密钥,参考: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;
}

第三步:构建分享内容并分享

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 (-代表您的项目名称)文件。为键值添加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:集成微信的特定方式

1、登录微信开放平台(《http://open.weixin.qq.com/》)成为微信开发者,创建应用以获取应用的 AppID 和 AppSecret。

2、返回您的项目,选择 -Info.plist(- 代表项目名称)文件。添加微信 URL Scheme 键,其值为微信 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(- 代表项目名称)文件。添加 Google+ URL Scheme 键和一个 URL 标识符键,其值都是 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;

simplyShare

#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)

showShareEditor

#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)