百度社会化服务分享是一个多平台的分享,下面只添加了一个新浪微博的单平台分享。
首先到百度社会化服务分享,下载资源包,并且把该资源包导入到你的项目中。
我只在.h文件中声明了一个可连接的button。
下面是.m文件。
#import "ViewController.h"
#import <BaiduSocialShare/BDSocialShareSDK.h>
#import "SBJson.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//定义分享平台数组
NSArray *platforms = [NSArrayarrayWithObjects:kBD_SOCIAL_SHARE_PLATFORM_SINAWEIBO,kBD_SOCIAL_SHARE_PLATFORM_QQWEIBO,kBD_SOCIAL_SHARE_PLATFORM_QQZONE,kBD_SOCIAL_SHARE_PLATFORM_KAIXIN,kBD_SOCIAL_SHARE_PLATFORM_RENREN,kBD_SOCIAL_SHARE_PLATFORM_WEIXIN_SESSION,kBD_SOCIAL_SHARE_PLATFORM_WEIXIN_TIMELINE,kBD_SOCIAL_SHARE_PLATFORM_QQFRIEND,
kBD_SOCIAL_SHARE_PLATFORM_EMAIL,
kBD_SOCIAL_SHARE_PLATFORM_SMS,nil];
//初始化分享组件
[BDSocialShareSDK registerApiKey:@"dHwDe5TTTtFEv4MOgoeTGLvX" andSupportPlatforms:platforms];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//点击按钮,调用分享的UI接口。
-(IBAction)doshare:(id)sender{
BDSocialShareContent *content=[BDSocialShareContent shareContentWithDescription:@"小武哥"url:@"http://developer.baidu.com/soc/share" title:@"百度社会化分享"];
[content addImageWithImageSource:[UIImage imageNamed:@"1"]imageUrl:@"http://www.imanhua.com/Cover/2013-05/ybhtdn.jpg"];
[BDSocialShareSDK showShareMenuWithShareContent:contentmenuStyle:BD_SOCIAL_SHARE_MENU_BOX_STYLE result:^(BD_SOCIAL_RESULT requestResult, NSString*platformType, id response, NSError *error) {
}];
最后得在Build Setting 中把Other Link Flag属性设置为-ObjC