示例:
#import "AppDelegate.h"
#import <ShareSDK/ShareSDK.h>
#import "WeiboSDK.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//1.初始化ShareSDK應用,字符串"iosv1101"是應該換成你申請的ShareSDK應用中的Appkey
[ShareSDK registerApp:@"567ca5dce0da"];
//2. 初始化社交平臺
//2.1 代碼初始化社交平臺的方法
[self initializePlat];
//2.2 使用後臺管理初始社交平臺的方法
// [self initializePlatForTrusteeship];
//3.設置根視圖控制器,如果沒有使用storyboard一定要設置。
return YES;
}
- (BOOL)application:(UIApplication *)application
handleOpenURL:(NSURL *)url
{
return [ShareSDK handleOpenURL:url wxDelegate:self];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [ShareSDK handleOpenURL:url
sourceApplication:sourceApplication
annotation:annotation
wxDelegate:self];
}
- (void)initializePlat
{
/**
連接新浪微博開放平臺應用以使用相關功能,此應用需要引用SinaWeiboConnection.framework
http://open.weibo.com上註冊新浪微博開放平臺應用,並將相關信息填寫到以下字段
**/
<span style="color:#ff0000;">[ShareSDK connectSinaWeiboWithAppKey:@"220713449"
appSecret:@"0ced62ad68f3fbbf2d00e41f2ba1e99e"
redirectUri:@"http://www.baidu.com"
weiboSDKCls:[WeiboSDK class]];</span>
}
點擊分享事件:
- (IBAction)share:(id)sender
{
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"image01" ofType:@"jpg"];
//1、構造分享內容
id<ISSContent> publishContent = [ShareSDK content:@"要分享的內容"
defaultContent:@"默認內容"
image:[ShareSDK imageWithPath:imagePath]
title:@"ShareSDK"
url:@"http://www.mob.com"
description:@"這是一條演示信息"
mediaType:SSPublishContentMediaTypeNews];
<span style="color:#ff0000;">[ShareSDK clientShareContent:publishContent //內容對象
type:ShareTypeSinaWeibo //平臺類型
statusBarTips:YES
result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {//返回事件
if (state == SSPublishContentStateSuccess)
{
NSLog(NSLocalizedString(@"TEXT_SHARE_SUC", @"分享成功!"));
}
else if (state == SSPublishContentStateFail)
{
NSLog(NSLocalizedString(@"TEXT_SHARE_FAI", @"分享失敗!"), [error errorCode], [error errorDescription]);
}
}];</span>
}