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

本文共 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

你可能感兴趣的文章
图解排序算法之快速排序-双端探测法
查看>>
mysql
查看>>
11月15日云栖精选夜读:分布式服务框架Dubbo疯狂更新!阿里开源要搞大事情?...
查看>>
Druid数据库连接池就这么简单
查看>>
Python最假的库:Faker
查看>>
IDE 插件新版本发布,开发效率 “biu” 起来了
查看>>
阿里云安全肖力:安全基础建设是企业数字化转型的基石
查看>>
Redis 基础、高级特性与性能调优
查看>>
BZT52C15S资料
查看>>
Laravel Telescope入门教程(上)
查看>>
Linux配置ip 及网络问题排查
查看>>
AndroidStudio用Cmake方式编译NDK代码(cmake配置.a库)
查看>>
OSChina 周四乱弹 ——黑丝短裙java程序员同事
查看>>
设置iptables之后不能正常访问ftp解决方法
查看>>
移动端rem布局
查看>>
jsp与iframe跨域访问的一个方法
查看>>
ViewPager + Fragment 取消预加载
查看>>
BigDecimal 02 - 注意事项
查看>>
用js玩桌球游戏
查看>>
maven下运行jetty报错
查看>>