美文网首页
iOS使用ShareSDK分享

iOS使用ShareSDK分享

作者: 靠北的北 | 来源:发表于2016-11-16 16:50 被阅读262次

1、到ShareSDK官网(http://www.mob.com/#/download)下载SDK,注册appkey。
2、将ShareSDK拖到工程。(也可以使用cocopods管理)
3、在APPDelegate.m

#import <ShareSDK/ShareSDK.h>

#import <ShareSDKConnector/ShareSDKConnector.h>

#import <TencentOpenAPI/TencentOAuth.h>//腾讯

#import <TencentOpenAPI/QQApiInterface.h>

#import "WXApi.h"//微信

#import "WeiboSDK.h"//新浪微博

4、在 AppDelegate.m 中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions ;方法中注册ShareSDK。

- (void)configShareSDK

{

 [ShareSDK registerApp:@"ShareSDK注册的appKey" activePlatforms:@[

 @(SSDKPlatformTypeSinaWeibo),

 @(SSDKPlatformTypeWechat),//这里可以根据实际情况选择微信好友,朋友圈等

 @(SSDKPlatformTypeQQ)]//这里同上

 onImport:^(SSDKPlatformType platformType) {

 

 switch (platformType)//与activePlatforms中注册的一致

 {

 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)
//与activePlatforms中注册的一致
 {

 case SSDKPlatformTypeSinaWeibo:

 [appInfo SSDKSetupSinaWeiboByAppKey:@"sinaWeibo注册的appkey"

 appSecret:@"密钥"

 redirectUri:@"http://www.sharesdk.cn"

 authType:SSDKAuthTypeBoth];

 break;

 case SSDKPlatformTypeWechat:

 [appInfo SSDKSetupWeChatByAppId:@"微信注册的appid"

 appSecret:@"密钥"];

 break;

 case SSDKPlatformTypeQQ:

 [appInfo SSDKSetupQQByAppId:@"腾讯QQ注册的appid"

 appKey:@"腾讯QQ注册的appkey"

 authType:SSDKAuthTypeBoth];

 break;

 default:

 break;

 }

 }];

}

注:1、所需的相关配置及代码在对应的开放平台上注册成为开发者。

5、使用ShareSDK分享

- (IBAction)clickShareBtn:(UIButton *)sender {

 

 NSArray* imageArray = @[[UIImage imageNamed:@"分享显示的图片(一般使用app的Icon)"]];

 NSString *htmlTitle = @"分享内容";

 if (!htmlTitle) {

 htmlTitle = @"";

 }

 NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];

 [shareParams SSDKSetupShareParamsByText:nil

 images:imageArray

 url:[NSURL URLWithString:self.urlStr]

 title:htmlTitle

 type:SSDKContentTypeAuto];

 [ShareSDK showShareActionSheet:nil items:nil shareParams:shareParams onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {

 //回调方法中会走成功或失败,监听分享状态可以在这里操作。

 }];

}

end:更多配置可以参考http://wiki.mob.com/ios简洁版快速集成/#h1-0

相关文章

  • ShareSDK

    1、ShareSDK2、iOS 集成 ShareSDK 分享

  • iOS使用ShareSDK分享

    1、到ShareSDK官网(http://www.mob.com/#/download)下载SDK,注册appke...

  • ShareSDK 分享

    ShareSDK-for-iOS 比较方便使用

  • 嘟嘟牛在线App踩过的坑

    ShareSDK分享 问题1:最近使用ShareSDK经常出现微信不能分享? 答:thumbImage: 这个要设...

  • 关于分享的小见解

    关于分享----shareSDK使用中遇到的一些问题 首先为shareSDK打个广告,shareSDK拥有下面这些...

  • iOS 分享-ShareSDK

    关于iOS的分享太常用也太多第三方,其中ShareSDK在使用上很方便,UI可自定义,完美!大致总结下集成思路,以...

  • iOS-三方服务相关

    本篇涵盖支付 、登录、分享细节过程等. 1.两步快速集成使用ShareSDK、微信支付、支付宝支付2.iOS 微信...

  • shareSDK 分享的注意事项 iOS端

    shareSDK的网址 1.在经过将近一周时间的开发,终于搞定ios分享了。 2.由于原来使用的是友盟的分享,因此...

  • 由于不支持的分享类型 无法分享到微信

    使用 ShareSDK的时候,遇到一个问题:由于不支持的分享类型 无法分享到微信 分析后发现是 ShareSDK...

  • 1.6 -CanOpenURL:failed for URL:"

    今天装IOS shareSDK ,发布后,点击分享按钮 出现这个错误 弄了半天才发现-------------> ...

网友评论

      本文标题:iOS使用ShareSDK分享

      本文链接:https://www.haomeiwen.com/subject/qbyrpttx.html