谁能帮我详细介绍下 新浪微博IOS SDK的功能和使用方法

谁能帮我详细介绍下 新浪微博IOS SDK的功能和使用方法,第1张

1 首先下载新浪微博的sdk包 2 申请新浪微博的开发者帐号,在开发过程中要用到开发者的key和密钥secret 具体申请的方式在《我的应用》,过程很简单,不再复述 3 将下载的sdk包打开demo工程,将demo工程中的SinaWeiBoSDK下的文件全部拷贝到自己的...

第一步:在targets->info->url types中添加一项,命名为wb+appid(到官网开放平台去申请)

第二步:写一个分享功能类

[objc] view plain copy print?

// 省略头文件

@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

外部调用上面封装的方法来实现功能

[objc] view plain copy print?

//

// 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]

}

// 这里是自己定制的d出分享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


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11956773.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存