GithubHelp home page GithubHelp logo

lhplastid / sharesdk-for-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mobclub/sharesdk-for-ios

0.0 1.0 0.0 245.3 MB

Home Page: http://www.sharesdk.cn

Objective-C 99.13% C 0.65% HTML 0.13% C++ 0.08%

sharesdk-for-ios's Introduction

ShareSDK is the most comprehensive social SDK in the world , which share easily with 40+ platforms , from around the world.This wiki mainly tells how to easily and fastly integrate ShareSDK.

(中文文档:http://wiki.mob.com/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97/)

How to integrate ShareSDK easily

Step 1:Import the ShareSDK to your project

  • 1、Download the latest version of the ShareSDK, then you will get the following files.

img

  • 2、Select the ShareSDK file and drag into your project (or just holding down the Control key on your keyboard and click your project,namely right-click your project, and choose “Add Files to …”).

then you will see the following window, check the "Copy items into destination group's folder (if needed)" and click "Finish" button.

img

  • 3、Now you have added the ShareSDK file to your project and it will look like this:

img

Step 2:add the necessary Framework

Indispensable Framework:

  1. SystemConfiguration.framework
  2. QuartzCore.framework
  3. CoreTelephony.framework
  4. libicucore.dylib
  5. libz.1.2.5.dylib
  6. Security.framework

Optional Framework:

necessary for the SSO Login of Sina weibo

  1. ImageIO.framework

necessary for the SSO Login of Tencent weibo(iOS6.0+)

  1. Social.framework
  2. Accounts.framework

necessary for the SSO Login of QZone or QQ Friend share

  1. libstdc++.dylib
  2. libsqlite3.dylib

necessary for Mail or SMS

  1. MessageUI.framework

necessary for Google+ platform

  1. CoreMotion.framework
  2. CoreLocation.framework
  3. MediaPlayer.framework
  4. CoreText.framework
  5. AssetsLibrary.framework

The steps of adding the framework:

img

Step3: import the header files and register for a Appkey

  • 1、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.

  • 2、Open AppDelegate.m to import the .h file

#import <ShareSDK/ShareSDK.h>

and add the initialize code to the -(BOOL)application: didFinishLaunchingWithOptions: method

-	(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions 
{     
       [ShareSDK registerApp:@"***"]; // *** is the AppKey that you just got 
       //……     
       return YES; 
}

Step 4:choose the platforms that you need and initialize them

Add the the initialized codes of platform that you need to the -(BOOL) application: didFinishLaunchingWithOptions: method

-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{     
[ShareSDK registerApp:@"***"];  //you just added it

//… … 

//Initialize SinaWeibo Application 
[ShareSDK connectSinaWeiboWithAppKey:@"3201194191"                              
appSecret:@"0334252914651e8f76bad63337b3b78f"                              
redirectUri:@"http://appgo.cn"];      
   
//Initialize QZone Application 
[ShareSDK connectQZoneWithAppKey:@"100371282"                              
appSecret:@"aed9b0303e3ed1e27bae87c33761161d"];   

//Initialize Facebook Application 
[ShareSDK connectFacebookWithAppKey:@"107704292745179"                              
appSecret:@"38053202e1a5fe26c80c753071f0b573"];   
  
//Initialize Twitter Application 
[ShareSDK connectTwitterWithConsumerKey:@"mnTGqtXk0TYMXYTN7qUxg"                              
consumerSecret:@"ROkFqr8c3m1HXqS3rm3TJ0WkAJuwBOSaWhPbZ9Ojuc"                              
redirectUri:@"http://www.sharesdk.cn"];    

//… … 
return YES;
}

}

PS:the parameters of above connect… method are relevant with the social platform.If you don’t have the platform’ application, then you should go that platform and create one.

Step 5:point out the rootViewController

If you create the project with storyboard ,then just ignore this step, the system will set the rootViewController automatically.

Otherwise,you must set the rootViewController in the -(BOOL)application: didFinishLaunchingWithOptions: method,or it may cause some error(s). The codes may look like this:

-	(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions 
{     
//……      
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen    
mainScreen] bounds]] autorelease];      
self.viewController = [[[UINavigationController alloc] init]
autorelease];             
self.window.rootViewController = self.viewController;     
[self.window makeKeyAndVisible];
       return YES; 
}

Step 6:construct the share content and share it

  • 1、Create an object that conforms to ISSContent protocol. Please refer to ShareSDK.h in ShareSDK.framework or ShareSDKDemo to get the specific usage.

  • 2、To show the share content view ,you need to call the showShareActionSheet… method.

  • 3、Share content event usually goes after the ViewDidAppear event, in response to some action(such as a button is pressed). If you really would like to click the button and show the share content view,then you may add the following codes to the buttonPressed method.

NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ShareSDK"  ofType:@"jpg"];  //make sure you actually have the picture in your project

//Create a share content object
id<ISSContent> publishContent = [ShareSDK content:@"Share Content"                                           
          defaultContent:@" The default share content. No content displayed"                                                            
image:[ShareSDK imageWithPath:imagePath]                                              
title:@"ShareSDK"                                          
  url:@"http://www.sharesdk.cn"                                           
description:@"This is a test message"                                             
  mediaType:SSPublishContentMediaTypeNews];

//show share content view 
[ShareSDK showShareActionSheet:nil                     
                       shareList:nil                     
                         content:publishContent         
                  statusBarTips:YES                      
                    authOptions:nil                      
                   shareOptions: nil                     
                          result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) 
{                                                
if (state == SSResponseStateSuccess)                                                            
{                                         
             NSLog(@"Share Success!");                                        
       }                                         
else if (state == SSResponseStateFail)                                                      
{                                         
NSLog(@"Share Fail,Error code:%d,Error description:%@", [error  
errorCode], [error errorDescription]);                                                
       }                             
}];

Congratulations!you make it and the result may look like the following snapshop.

img

img

Option 1:The way to share content for iPad

  • 1、If you need to use ShareSDK on the iPad,you need to use the +container method of ShareSDK class to create an object that conforms to ISSContainer protocol. and call setIPadContainer series method to set the iPad container.

  • 2、In general, 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.

  • 3、Call the showShareActionSheet… method. And notice that the above container object should be one of the parameters. Here is an example:

//1,Create a container object
id<ISSContainer> container = [ShareSDK container]; 

//2,set the iPad container(in this example sender is a button)
[container setIPadContainerWithView:sender  
                          arrowDirect:UIPopoverArrowDirectionUp];

//3,Pop-up the share menu 
[ShareSDK showShareActionSheet:container                          
                   shareList:nil       
                     content:publishContent         
              statusBarTips:YES                         
                authOptions:authOptions                        
               shareOptions:shareOptions                          
                      result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) 
{                                 
     if (state == SSResponseStateSuccess)                                 
     {                                     
         NSLog(@"Share Success!");                                 
     }                                 
     else if (state == SSResponseStateFail)                                 
     {                                     
         NSLog(@"Share Fail,Error code:%d,Error description:%@", 
         [error errorCode], [error errorDescription]);                                 
     }                             
}]; 

Option 2:Use “The Sever Hosting” Mode to initialize SDK

  • 1、The Sever Hosting mode is a way that never need to initialize the social platform information in code any more.You can just set the social platform informations(such as Appkey、AppSecret etc) in mob management background system(http://dashboard.mob.com/). And it looks like this:

img

  • 2、Here are the codes that replace the Step 3 and Step 4 to initialize the ShareSDK and social platforms:
#import <ShareSDK/ShareSDK.h>
-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{     
//[ShareSDK registerApp:@"***"]; // *** is the Appkey of Mob app

// Here is the way of using The Sever Hosting mode
//the parameter YES means use The Sever Hosting mode
      [ShareSDK registerApp:@"***" useAppTrusteeship:YES];    
      //……      
      return YES; 
}
  • 3、When changing the configuration information of Mob application in The Server Hosting mode, it needs some time(about 15 minutes) to really get worked. SDK provides a waitAppSettingComplete methods to make sure the change is getting works.You can use it like this:
[ShareSDK waitAppSettingComplete:^{          
      // Calls the ShareSDK API  
}];

Option 3:the specific way to integrate WeChat

  • 1、Log in to WeChat open platform (http://open.weixin.qq.com/) to become a WeChat developer and create a application to get the app’s AppID,AppSecret.

  • 2、Back to your project,choose the -Info.plist (- represents your project name) file. Add a WeChat URL Scheme key, the value is WeChat AppID (eg: wx4868b35061f87885). Here is a example:

img

  • 3、Open -AppDelegate.m ( -represents your project name), import WeChat SDK’s header file:
#import "WXApi.h"

Check whether the handleOpenURL method had been added, if not then add the following codes(in AppDelegate.m file):

-	(BOOL)application:(UIApplication *)application  handleOpenURL:(NSURL *)url 
{     
return [ShareSDK handleOpenURL:url wxDelegate:self]; 
} 

 - (BOOL)application:(UIApplication *)application                 openURL:(NSURL *)url   sourceApplication:(NSString *)sourceApplication                 annotation:(id)annotation 
{     
      return [ShareSDK handleOpenURL:url       
sourceApplication:sourceApplication                      
        annotation:annotation         
        wxDelegate:self]; 
}
  • 4、Native code mode

There are 2 methods to share content to WeChat,but if you want to use WeChat account to authorize and get the user’s information ,you need to use the method with appSecret parameter.

-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
      //...         
//Initialize WeChat Application 
//The parameter “wx6dd7a9b94f3dd72a” is the AppID of WeChat App   
//[ShareSDK connectWeChatWithAppId:@"wx6dd7a9b94f3dd72a"                                 
//                         wechatCls:[WXApi class]];     

//you can use WeChat account to authorize using this method
[ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
                      appSecret:@"64020361b8ec4c99936c0e3999a9f249"  
                      wechatCls:[WXApi class]];
      
      //... 
}

  • 5、The Server hosting mode

There’s not need to initialize the application configuration by code in this mode. Since ShareSDK relies on WeChat SDK to share, so you still need to add a line of code in - application: didFinishLaunchingWithOptions: method, to import the WeChat SDK classes. Here is the example:

-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
//...        
// Add the WeChat SDK if your project or ShareSDK still don’s have one
      [ShareSDK importWeChatClass:[WXApi class] ];         
//... 
}

Option 4:the specific way to integrate QQ

  • 1、Log in to Open QQ platform (http://open.qq.com/)to become a developer and create a application to get the app’s AppID.

  • 2、Back to your project, choose the -Info.plist (- represents your project name) file. Add a URL Scheme for key, the value’s format is: "QQ" +the hexadecimal number of AppID (if the length of hexadecimal number is less than 8,then fill with zero to make sure the length is 8). Here is a example,if the hexadecimal number of your AppID is 5FB8B52,then the final value of the URL Scheme is QQ05FB8B52.

img

  • 3、Open -AppDelegate.m ( -represents your project name), import QQSDK SDK header file:
#import <TencentOpenAPI/QQApiInterface.h> 
#import <TencentOpenAPI/TencentOAuth.h>

Check whether the handleOpenURL method is added, if not then add the following codes(in AppDelegate.m file):

-	(BOOL)application:(UIApplication *)application  handleOpenURL:(NSURL *)url 
{     
return [ShareSDK handleOpenURL:url wxDelegate:self]; 
} 

- (BOOL)application:(UIApplication *)application                 openURL:(NSURL *)url   sourceApplication:(NSString *)sourceApplication                 annotation:(id)annotation 
{     
      return [ShareSDK handleOpenURL:url       
sourceApplication:sourceApplication                      
        annotation:annotation         
        wxDelegate:self]; 
}
  • 4、Native code mode

Add the codes in -(BOOL)application: didFinishLaunchingWithOptions: method

-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
      //...        
//Initialize QQ Platform  
//The parameter “100371282” is the AppID of QQ App   
[ShareSDK connectQQWithQZoneAppKey:@"100371282"                                              
                   qqApiInterfaceCls:[QQApiInterface class]                            
                     tencentOAuthCls:[TencentOAuth class] ];
      
      //... 
}
  • 5、The Server hosting mode

There’s not need to initialize the application configuration by code in this mode. Since ShareSDK relies on QQ SDK to share, so you still need to add a line of code in- application: didFinishLaunchingWithOptions: method, to import the QQ SDK classes. Here is the example:

-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
      //...        
// Add the QQ SDK if your project or ShareSDK still don’s have one 
[ShareSDK importQQClass:[QQApiInterface class]                   
         tencentOAuthCls:[TencentOAuth class] ];          
      //... 
}

Option 5:the specific way to integrate Google+

  • 1、 Log in to Google+ Developer platform to become a developer (https://code.google.com/apis/console/) and create a application to get the app’s ClientID、ClientSecret、redirectUri etc.

  • 2、Back to your project , add “-ObjC” to Other linker flags. Here are steps:

img

  • 3、Back to your project , choose the -Info.plist (- represents your project name) file. Add a Google+ URL Scheme key and a URL identifier key, the value both are the BundleID (eg cn.appgo.sharebyone). Here are steps:

img

  • 4、Open -AppDelegate.m ( -represents your project name), import Google+ SDK header file:
#import <GoogleOpenSource/GoogleOpenSource.h>
#import <GooglePlus/GooglePlus.h>

Check whether the handleOpenURL method had been added, if not add the following codes(in AppDelegate.m file):

- (BOOL)application:(UIApplication *)application  handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url
                            wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
                sourceApplication:(NSString *)sourceApplication
                annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                   sourceApplication:sourceApplication
                   annotation:annotation
                   wxDelegate:self];
}
  • 5、Native code mode

Add the codes in -(BOOL)application: didFinishLaunchingWithOptions: method

-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
      //...        
//Initialize Google+ Platform  
//the Google+ app’s ClientID、ClientSecret、redirectUri 
      [ShareSDK connectGooglePlusWithClientId:
                 @"232554794995.apps.googleusercontent.com"                                                  
                 clientSecret:@"PEdFgtrMw97aCvf0joQj7EMk"                                                                                        
                 redirectUri:@"http://localhost"                                                                                                            
                 signInCls:[GPPSignIn class]                                               
                 shareCls:[GPPShare class] ];
      
      //... 
}
  • 6、The Server hosting mode

There’s not need to initialize the application configuration by code in this mode. Since ShareSDK relies on Google+ SDK to share, so you still need to add a line of code in - application: didFinishLaunchingWithOptions: method, to import the Google+ SDK classes. Here is the example:

-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
      //...        
// Add the Google+ SDK if your project or ShareSDK still don’s have one 
[ShareSDK importGooglePlusClass:[GPPSignIn class]                              
                       shareClass:[GPPShare class] ];
      //... 
}

Option 6:the specific way to integrate Pinterest

  • 1、Log in to Pinterest developer platform (http://developers.pinterest.com/) to become a developer and Create a application to get the app’s ClientID.

  • 2、Back to your project,choose the -Info.plist (- represents your project name) file. Add a WeChat URL Scheme key, and the value is: pin + ClientID (eg: pin1432928). Here is a example:

img

  • 3、Open -AppDelegate.m ( -represents your project’s name), import Pinterest SDK header file:
#import <Pinterest/Pinterest.h>

Check whether the handleOpenURL method had been added, if not add the following codes(in AppDelegate.m file):

- (BOOL)application:(UIApplication *)application  handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url
                            wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
                sourceApplication:(NSString *)sourceApplication
                annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                   sourceApplication:sourceApplication
                   annotation:annotation
                   wxDelegate:self];
}
  • 4、Native code mode

Add the codes in -(BOOL)application: didFinishLaunchingWithOptions: method

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
       //...

       //Initialize Pinterest
       [ShareSDK connectPinterestWithClientId:@"1432928"       //This parameter is the application ClientID
                                pinterestCls:[Pinterest class] ];


       //...
}
  • 5、The Server hosting mode

There’s not need to initialize the application configuration by code in this mode. Since ShareSDK relies on Pinterest SDK to share, so you still need to add a line of code in - application: didFinishLaunchingWithOptions: method, to import the Pinterest SDK classes. Here is the example:

[ShareSDK importPinterestClass:[Pinterest class] ];

Option 7:the specific way to integrate YiXin

  • 1、Log in to YiXin open platform (http://open.yixin.im/) to become a YiXin developer and create a application to get the app’s AppID.

  • 2、Back to your project,choose the -Info.plist (- represents your project name) file. Add a YiXin URL Scheme key, the value is YiXin AppID (eg: yx0d9a9f9088ea44d78680f3274da1765f). Here is a example:

img

  • 3、Open -AppDelegate.m ( -represents your project name), import YiXin SDK header file:
#import "YXApi.h"

Check whether the handleOpenURL method is added, if not then add the following codes(in AppDelegate.m file):

- (BOOL)application:(UIApplication *)application  handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url
                            wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
                sourceApplication:(NSString *)sourceApplication
                annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                   sourceApplication:sourceApplication
                   annotation:annotation
                   wxDelegate:self];
}
  • 4、Native code mode

Add the codes in -(BOOL)application: didFinishLaunchingWithOptions: method

-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
      //...        
//Initialize YiXin Platform  
//The parameter “yx0d9a9f9088ea44d78680f3274da1765f” is the AppID 
[ShareSDK connectYiXinWithAppId:
                             @"yx0d9a9f9088ea44d78680f3274da1765f"                              
                         yixinCls:[YXApi class] ];
      
      //... 
}

  • 5、The Server hosting mode

There’s not need to initialize the application configuration by code in this mode. Since ShareSDK relies on YiXin SDK to share, so you still need to add a line of code in - application: didFinishLaunchingWithOptions: method, to import the YiXin SDK classes. Here is the example:

-	(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
      //...        
// Add the YiXin SDK if your project or ShareSDK still don’s have one 
      [ShareSDK importYiXinClass:[YXApi class] ];
       
      //... 
}

sharesdk-for-ios's People

Contributors

gz-mob avatar jinghuangliu avatar vimfung avatar

Watchers

Rex Lv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.