iOS ShareSDK 分享到新浪微博
来源:互联网 发布:mac最安全ntfs 编辑:程序博客网 时间:2024/03/29 05:06
第一步:在targets->info->url types中添加一项,命名为wb+appid(到官网开放平台去申请)
第二步:写一个分享功能类
// 省略头文件@interface HYBShareSDKHelper : NSObject+ (void)registerShareSDK;+ (BOOL)handleOpenURL:(NSURL *)url;+ (BOOL)handleOpenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;// 调用此方法来分享信息typedef void (^HYBShareCompletion)(BOOL successful);+ (void)shareWithContent:(NSString *)content toController:(UIViewController *)controller pngImage:(UIImage *)pngImage title:(NSString *)title url:(NSString *)url mediaType:(SSPublishContentMediaType)mediaType shareViewDelegate:(id<ISSShareViewDelegate>)shareViewDelegate completion:(HYBShareCompletion)completion;@end
外部调用上面封装的方法来实现功能
//// HYBShareSDKHelper.m// CustomSharedSDKDemo// #import "HYBShareSDKHelper.h"#import "HYBAppCommonInfoTool.h"#import "HYBShareView.h"#define kShareSDKAppKey @""#define kShareSDKAppSecret @""#define kSinaWeiboAppKey @""#define kSinaWeiboAppSecret @""@implementation HYBShareSDKHelper+ (void)registerShareSDK { [ShareSDK registerApp:kShareSDKAppKey]; // 添加新浪微博应用 NSString *redirectUri = @""; // 添加新浪微博应用 [ShareSDK connectSinaWeiboWithAppKey:kSinaWeiboAppKey appSecret:kSinaWeiboAppSecret redirectUri:redirectUri]; // 当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台 [ShareSDK connectSinaWeiboWithAppKey:kSinaWeiboAppKey appSecret:kSinaWeiboAppSecret redirectUri:redirectUri weiboSDKCls:[WeiboSDK class]]; return;}+ (BOOL)handleOpenURL:(NSURL *)url { return [ShareSDK handleOpenURL:url wxDelegate:self];}+ (BOOL)handleOpenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];}// 这里是自己定制的弹出分享UI+ (void)showShareViewInController:(UIViewController *)controller completion:(HYBShareClickBlock)completion { HYBShareView *sv = [[HYBShareView alloc] initWithImages:@[@"sns_wx_icon", @"sns_wx_fr_icon", @"sns_qq_icon", @"sns_qzone_icon", @"sns_sina_icon"] titles:@[@"微信好友", @"微信朋友圈", @"QQ好友", @"QQ空间", @"新浪微博"] completion:^(NSUInteger index) { if (completion) { completion(index); } }]; [sv showInController:controller];}+ (void)shareWithContent:(NSString *)content toController:(UIViewController *)controller pngImage:(UIImage *)pngImage title:(NSString *)title url:(NSString *)url mediaType:(SSPublishContentMediaType)mediaType shareViewDelegate:(id<ISSShareViewDelegate>)shareViewDelegate completion:(HYBShareCompletion)completion { // 分享内容 id<ISSContent> sharedContent = [ShareSDK content:content defaultContent:content image:[ShareSDK pngImageWithImage:pngImage] title: title url:url description:@"自己看着办" mediaType:mediaType]; // 验证参数 id<ISSAuthOptions> authOptions = [ShareSDK authOptionsWithAutoAuth:YES allowCallback:YES authViewStyle:SSAuthViewStyleFullScreenPopup viewDelegate:nil authManagerViewDelegate:nil]; // 显示分享列表 [self showShareViewInController:controller completion:^(NSUInteger index) { if (index == 4) {// 新浪微博 [self shareToSinaWeiboWithContent:sharedContent authOptions:authOptions content:content pngImage:pngImage completion:^(BOOL successful) { if (completion) { completion(successful); } }]; } }];}// 分享到Sina weibo+ (void)shareToSinaWeiboWithContent:(id<ISSContent>)sharedContent authOptions:(id<ISSAuthOptions>)authOptions content:(NSString *)content pngImage:(UIImage *)pngImage completion:(HYBShareCompletion)completion { [sharedContent addSinaWeiboUnitWithContent:content image:[ShareSDK pngImageWithImage:pngImage]]; // if haven authorized, then call if (![ShareSDK hasAuthorizedWithType:ShareTypeSinaWeibo]) { [ShareSDK authWithType:ShareTypeSinaWeibo options:authOptions result:^(SSAuthState state, id<ICMErrorInfo> error) { if (state == SSAuthStateSuccess) { id<ISSShareOptions> shareOptions = [ShareSDK simpleShareOptionsWithTitle:@"美容总监" shareViewDelegate:nil]; [ShareSDK clientShareContent:sharedContent type:ShareTypeSinaWeibo authOptions:authOptions shareOptions:shareOptions statusBarTips:YES result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) { if (completion && end) { DDLogVerbose(@"%@", error.errorDescription); completion(state == SSPublishContentStateSuccess); } }]; } }]; } else {// use client share to Sina App Client id<ISSShareOptions> shareOptions = [ShareSDK simpleShareOptionsWithTitle:@"美容总监" shareViewDelegate:nil]; [ShareSDK clientShareContent:sharedContent type:ShareTypeSinaWeibo authOptions:authOptions shareOptions:shareOptions statusBarTips:YES result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) { if (completion && end) { DDLogVerbose(@"%@", error.errorDescription); completion(state == SSPublishContentStateSuccess); } }]; }}@end
2 1
- iOS ShareSDK 分享到新浪微博
- iOS ShareSDK 分享到新浪微博
- Android使用ShareSDK分享到新浪微博
- iOS ShareSDK 新浪微博分享遇到的坑
- shareSDK新浪微博分享的总结
- ios 分享到新浪微博
- ios 分享到新浪微博
- ios 分享到新浪微博
- iOS ShareSDK的新浪微博配置
- 使用ShareSDK分享到新浪微博遇到的一些问题
- 【ShareSDK社会化分享】新浪微博分享网络图片问题
- 【ShareSDK社会化分享】新浪微博分享网络图片问题
- IOS 使用ShareSDK进行QQ,微信,新浪微博分享失败经验
- iOS ShareSDK 新浪微博分享sos package or sign error
- cocos2d-x手机游戏(IOS版本)接入分享shareSDK(新浪微博和微信分享)记录
- ShareSDK for Android 只有新浪微博分享
- ShareSDK for Android 只有新浪微博分享
- Android通过ShareSDK实现新浪微博分享
- VIM每日一技(1)—visual block操作
- Linux下僵尸进程的处理
- 深入理解JavaScript系列(36):设计模式之中介者模式
- 日经社説 20150211 ウクライナ停戦調停を生かせ
- 寻找最小的k个数
- iOS ShareSDK 分享到新浪微博
- C# 回调函数
- 计算组合数
- error at ::0 can't find referenced pointcut...解决方法
- 日经社説 20150211 国際環境の変化が促すODAの改革
- 深入理解JavaScript系列(37):设计模式之享元模式
- The Log: What every software engineer should know about real-time data's unifying abstraction
- IOS实现后台播放音乐
- c++/c 获取cpp文件行号跟文件名