博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS第三方分享-ShareSDK
阅读量:5873 次
发布时间:2019-06-19

本文共 10395 字,大约阅读时间需要 34 分钟。

网址链接:http://mob.com/Download/detail?type=1&plat=2

由于新版的简单分享很多功能都有,而且打包后体积比全版本的少了几M所以在这里用这个

1.在官网下载SDK并导入相应的framework(比起之前的少了很多库)

2.初始化ShareSDK(因为,一般分享的话就这几个平台,全部集成下)

AppDelegate中导入头文件

//ShareSDK必要头文件#import 
#import
//腾讯开放平台(对应QQ和QQ空间)SDK头文件#import
#import
//微信SDK头文件#import "WXApi.h"//新浪微博SDK头文件#import "WeiboSDK.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions NS_AVAILABLE_IOS(3_0);

[ShareSDK registerApp:@"iosv1101"          activePlatforms:@[                            @(SSDKPlatformTypeSinaWeibo),                            @(SSDKPlatformTypeTencentWeibo),                            @(SSDKPlatformTypeMail),                            @(SSDKPlatformTypeSMS),                            @(SSDKPlatformTypeCopy),                            @(SSDKPlatformTypeFacebook),                            @(SSDKPlatformTypeTwitter),                            @(SSDKPlatformTypeWechat),                            @(SSDKPlatformTypeQQ),                            @(SSDKPlatformTypeDouBan)]                 onImport:^(SSDKPlatformType platformType) {                                          switch (platformType)                     {                         case SSDKPlatformTypeWechat:                             [ShareSDKConnector connectWeChat:[WXApi class]];                             break;                         case SSDKPlatformTypeQQ:                             [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth 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 SSDKPlatformTypeTencentWeibo:                      //设置腾讯微博应用信息,其中authType设置为只用Web形式授权                      [appInfo SSDKSetupTencentWeiboByAppKey:@"801307650"                                                   appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"                                                 redirectUri:@"http://www.sharesdk.cn"];                      break;                  case SSDKPlatformTypeFacebook:                      //设置Facebook应用信息,其中authType设置为只用SSO形式授权                      [appInfo SSDKSetupFacebookByAppKey:@"107704292745179"                                               appSecret:@"38053202e1a5fe26c80c753071f0b573"                                                authType:SSDKAuthTypeBoth];                      break;                  case SSDKPlatformTypeTwitter:                      [appInfo SSDKSetupTwitterByConsumerKey:@"LRBM0H75rWrU9gNHvlEAA2aOy"                                              consumerSecret:@"gbeWsZvA9ELJSdoBzJ5oLKX0TU09UOwrzdGfo9Tg7DjyGuMe8G"                                                 redirectUri:@"http://mob.com"];                      break;                  case SSDKPlatformTypeWechat:                      [appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"                                            appSecret:@"64020361b8ec4c99936c0e3999a9f249"];                      break;                  case SSDKPlatformTypeQQ:                      [appInfo SSDKSetupQQByAppId:@"100371282"                                           appKey:@"aed9b0303e3ed1e27bae87c33761161d"                                         authType:SSDKAuthTypeBoth];                      break;                  case SSDKPlatformTypeDouBan:                      [appInfo SSDKSetupDouBanByApiKey:@"02e2cbe5ca06de5908a863b15e149b0b"                                                secret:@"9f1e7b4f71304f2f"                                           redirectUri:@"http://www.sharesdk.cn"];                      break;                  default:                      break;              }                        }];

以上是ShareSDK测试用的key,自己做程序的时候需要在ShareSDK申请,各个平台的key也要在各个平台申请

3.ShareSDK的使用

导入头文件

#import 
#import
#import
#import
#pragma mark - 菜单分享- (void)menuShareTest {    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];    [shareParams SSDKSetupShareParamsByText:@"分享内容"                                     images:nil                                        url:[NSURL URLWithString:@"http://mob.com"]                                      title:@"分享标题"                                       type:SSDKContentTypeImage];        [ShareSDK showShareActionSheet:nil                                                                items:@[                                                                             @(SSDKPlatformTypeSinaWeibo),                                                                             @(SSDKPlatformTypeTencentWeibo),                                                                             @(SSDKPlatformSubTypeWechatSession),                                                                             @(SSDKPlatformSubTypeWechatTimeline),       @(SSDKPlatformSubTypeQQFriend),                                                                             @(SSDKPlatformSubTypeQZone),                                                                             @(SSDKPlatformTypeWechat)]                                                               shareParams:shareParams                                                       onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {                                                           NSLog(@"-0-");                                                       }];    //删除和添加//    [sheet.directSharePlatforms removeObject:@(SSDKPlatformTypeWechat)];//    [sheet.directSharePlatforms addObject:@(SSDKPlatformTypeSinaWeibo)];}#pragma mark - 单个分享- (void)onlyShareTest {    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];    [shareParams SSDKSetupShareParamsByText:@"分享内容"                                         images:nil                                            url:[NSURL URLWithString:@"http://mob.com"]                                          title:@"分享标题"                                           type:SSDKContentTypeImage];    [ShareSDK share:SSDKPlatformTypeSinaWeibo parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {        switch (state) {            case SSDKResponseStateSuccess:            {                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"                                                                    message:nil                                                                   delegate:nil                                                          cancelButtonTitle:@"确定"                                                          otherButtonTitles:nil];                [alertView show];                break;            }            case SSDKResponseStateFail:            {                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享失败"                                                                    message:[NSString stringWithFormat:@"%@", error]                                                                   delegate:nil                                                          cancelButtonTitle:@"确定"                                                          otherButtonTitles:nil];                [alertView show];                break;            }            case SSDKResponseStateCancel:            {                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享已取消"                                                                    message:nil                                                                   delegate:nil                                                          cancelButtonTitle:@"确定"                                                          otherButtonTitles:nil];                [alertView show];                break;            }            default:                break;        }    }];}#pragma mark - 一键分享- (void)onceShareTest {      //构造分享参数    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];    [shareParams SSDKSetupShareParamsByText:@"我在使用ShareSDK的一键分享。"                                         images:nil                                            url:nil                                          title:nil                                           type:SSDKContentTypeImage];        [SSEShareHelper oneKeyShare:@[@(SSDKPlatformTypeSinaWeibo), @(SSDKPlatformTypeTencentWeibo)] parameters:nil onStateChanged:^(SSDKPlatformType platformType, SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {        NSString *platformName = nil;        switch (platformType)        {            case SSDKPlatformTypeSinaWeibo:                platformName = @"新浪微博";                break;            case SSDKPlatformTypeTencentWeibo:                platformName = @"腾讯微博";                break;            default:                break;        }    }];}#pragma mark - 第三方登录(信息获取)- (void)threeShareTest {    [ShareSDK getUserInfo:SSDKPlatformTypeSinaWeibo onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {        NSLog(@"平台类型根据枚举查看:%ld",(unsigned long)user.platformType);        NSLog(@"授权就不为空:%@",user.credential);        NSLog(@"uid:%@",user.uid);        NSLog(@"昵称:%@",user.nickname);        NSLog(@"图片地址:%@",user.icon);        NSLog(@"性别:%ld",(unsigned long)user.gender);    }];}#pragma mark - 其他- (void)other {    //判断是否授权    [ShareSDK hasAuthorized:SSDKPlatformTypeSinaWeibo];}

 

转载于:https://www.cnblogs.com/hxwj/p/4739669.html

你可能感兴趣的文章
飞秋无法显示局域网好友
查看>>
学员会诊之03:你那惨不忍睹的三层架构
查看>>
vue-04-组件
查看>>
Golang协程与通道整理
查看>>
解决win7远程桌面连接时发生身份验证错误的方法
查看>>
C/C++ 多线程机制
查看>>
js - object.assign 以及浅、深拷贝
查看>>
python mysql Connect Pool mysql连接池 (201
查看>>
Boost在vs2010下的配置
查看>>
android camera(四):camera 驱动 GT2005
查看>>
一起谈.NET技术,ASP.NET伪静态的实现及伪静态的意义
查看>>
20款绝佳的HTML5应用程序示例
查看>>
string::c_str()、string::c_data()及string与char *的正确转换
查看>>
11G数据的hive初测试
查看>>
如何使用Core Text计算一段文本绘制在屏幕上之后的高度
查看>>
==和equals区别
查看>>
2010技术应用计划
查看>>
XML 节点类型
查看>>
驯服 Tiger: 并发集合 超越 Map、Collection、List 和 Set
查看>>
Winform开发框架之权限管理系统改进的经验总结(3)-系统登录黑白名单的实现...
查看>>