详解iOS社会化分享集成

2020-01-21 04:36:12刘景俊

ii.打开AppDelegate.m(代表你的工程名字)导入头文件**


#import <span style="color: rgb(101, 123, 131); font-family: Menlo; font-size: 9pt; line-height: 1.8em;"><ShareSDK/ShareSDK.h></span><br data-filtered="filtered"><sharesdk sharesdk.h=""> #import <span style="color: rgb(101, 123, 131); font-family: Menlo; font-size: 9pt; line-height: 1.8em;"><ShareSDKConnector/ShareSDKConnector.h></span><sharesdkconnector sharesdkconnector.h="">
//腾讯开放平台(对应QQ和QQ空间)SDK头文件
#import <span style="color: rgb(101, 123, 131); font-family: Menlo; font-size: 9pt; line-height: 1.8em;"> <TencentOpenAPI/TencentOAuth.h></span><tencentopenapi tencentoauth.h="">
 #import <span style="color: rgb(101, 123, 131); font-family: Menlo; font-size: 9pt; line-height: 1.8em;"><TencentOpenAPI/QQApiInterface.h></span><tencentopenapi qqapiinterface.h="">
//微信SDK头文件
#import "WXApi.h" 
 //新浪微博SDK头文件
 #import "WeiboSDK.h"</tencentopenapi></tencentopenapi></sharesdkconnector></sharesdk>

 

iii.在- (BOOL)application: didFinishLaunchingWithOptions:方法中调用registerActivePlatforms方法来初始化


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {** 
 
  // Override point for customization after application launch.
 
  [ShareSDK registerActivePlatforms:@[
        @(SSDKPlatformTypeSinaWeibo), 
        @(SSDKPlatformTypeWechat), 
        @(SSDKPlatformTypeQQ)] 
     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.easck.com/pre>

(4)添加分享代码

i.需要在分享的视图中导入的头文件


<span class="15" style="line-height: 1.8em; font-family: Menlo; color: rgb(101, 123, 131); font-size: 9pt; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"> </span><span style="line-height: 1.8em; font-family: Menlo; color: rgb(101, 123, 131); font-size: 9pt; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">#import <ShareSDK/ShareSDK.h></span>