ShareSDK分享

一、导入SDK包并且加入依赖库

//==========ShareSDK头文件====================

#import <ShareSDK/ShareSDK.h>

#import <ShareSDKConnector/ShareSDKConnector.h>

//以下是ShareSDK必须添加的依赖库:

//1libicucore.dylib

//2libz.dylib

//3libstdc++.dylib

//4JavaScriptCore.framework

 

//==========以下是各个平台SDK的头文件,根据需要继承的平台添加===

//腾讯开放平台(对应QQQQ空间)SDK头文件

#import <TencentOpenAPI/TencentOAuth.h>

#import <TencentOpenAPI/QQApiInterface.h>

//以下是腾讯SDK的依赖库:

//libsqlite3.dylib

 

//微信SDK头文件

#import "WXApi.h"

//以下是微信SDK的依赖库:

//libsqlite3.dylib

 

//新浪微博SDK头文件

#import "WeiboSDK.h"

//新浪微博SDK需要在项目Build Settings中的Other Linker Flags添加"-ObjC"

//以下是新郎微博SDK的依赖库:

//ImageIO.framework

 

//人人SDK头文件

#import <RennSDK/RennSDK.h>

 

//GooglePlus SDK头文件

#import <GooglePlus/GooglePlus.h>

//以下是GooglePlus SDK的依赖库

//1CoreMotion.framework

//2CoreLocation.framework

//3MediaPlayer.framework

//4AssetsLibrary.framework

//5AddressBook.framework

二、设置ShareSDK的AppKey并初始化社交平台

 

     *  设置ShareSDKappKey,如果尚未在ShareSDK官网注册过App,请移步到http://mob.com/login登录后台进行应用注册,

     *  在将生成的AppKey传入到此方法中。

     *  方法中的第二个参数用于指定要使用哪些社交平台,以数组形式传入。第三个参数为需要连接社交平台SDK时触发,

     *  在此事件中写入连接代码。第四个参数则为配置本地社交平台时触发,根据返回的平台类型来配置平台信息。

     *  如果您使用的时服务端托管平台信息时,第二、四项参数可以传入nil,第三项参数则根据服务端托管平台来决定要连接的社交SDK

 

    

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [ShareSDK registerApp:@"~~~"
          activePlatforms:@[@(SSDKPlatformTypeWechat)]
                 onImport:^(SSDKPlatformType platformType) {
                     switch (platformType) {
                         case SSDKPlatformTypeWechat:
                             [ShareSDKConnector connectWeChat:[WXApi class]];
                             break;
                         default:
                             break;
                     }
                 } onConfiguration:^(SSDKPlatformType platformType,
                                     NSMutableDictionary *appInfo) {
                     switch (platformType) {
                         case SSDKPlatformTypeWechat:
                             [appInfo SSDKSetupWeChatByAppId:@"~~~~~~~"
                                                   appSecret:@"~~~~~~~~"];
                             break;
                         default:
                             break;
                     }
                     
                 }];
    return YES;
}

 三、添加实现代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareButton setTitle:@"分享" forState:UIControlStateNormal];
    [shareButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    shareButton.frame = CGRectMake(20, 50, 200, 60);
    [shareButton addTarget:self action:@selector(shareButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shareButton];
}

-(void)shareButtonClick:(id)sender
{
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                     images:@[[UIImage imageNamed:@"a_wenzhang_share.png"]]
                                        url:[NSURL URLWithString:@"http://mob.com"]
                                      title:@"分享标题"
                                       type:SSDKContentTypeWebPage];
    [shareParams SSDKSetupWeChatParamsByText:@"微信分享" 
                                       title:@"分享标题"
                                         url:[NSURL URLWithString:@"http://mob.com"]
                                  thumbImage:nil
                                       image:@[[UIImage imageNamed:@"btn_sharetoweixin.png"]]
                                musicFileURL:nil
                                     extInfo:nil
                                    fileData:nil
                                emoticonData:nil
                                        type:SSDKContentTypeWebPage
                          forPlatformSubType:SSDKPlatformTypeWechat];
    [ShareSDK showShareActionSheet:sender
                             items:nil
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                   switch (state) {
                       case SSDKResponseStateSuccess:
                           NSLog(@"分享成功");
                       case SSDKResponseStateFail:
                           NSLog(@"分享失败");
                           break;
                           
                       default:
                           break;
                   }
               }];
}

 其中实现的是一个简单按钮实现微信分享。

猜你喜欢

转载自1395014506.iteye.com/blog/2243377