本文主要是介绍社会化分享 SDK,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
iOS 开发环境
- 了解配置iOS开发环境的详细信息,请参考https://developer.apple.com。
- 请您下载iOS 组件:SDK下载
2. 解压所下载的包,从BaiduSocialShare目录中得到所需要的所有的库:
BaiduSocialShare.framework
BaiduSocialShareSource.bundle
5. 在工程中添加社会化分享组件运行所需要的framework
SystemConfiguration.framework
QuartzCore.framework
UIKit.framework
Foundation.framework
CoreGraphics.framework
MessageUI.framework
CoreTelephony.framework
libsqlite3.dylib
libstdc++.dylib
libz.dylib
#import <BaiduSocialShare/BDSocialShareSDK.h>
// the key for API key
#define kBD_SOCIAL_SHARE_API_KEY @"SzxPfPb1dw9WcFzdEE8u7can"
- (void)viewDidLoad
{[super viewDidLoad];[self initializeBaiduSocialSDK];// Do any additional setup after loading the view, typically from a nib.
}- (void)initializeBaiduSocialSDK
{// decleare the platforms to shareNSArray *platforms = [NSArray arrayWithObjects:kBD_SOCIAL_SHARE_PLATFORM_SINAWEIBO,kBD_SOCIAL_SHARE_PLATFORM_QQWEIBO,kBD_SOCIAL_SHARE_PLATFORM_QQZONE,kBD_SOCIAL_SHARE_PLATFORM_KAIXIN,nil];// initialize baidu share SDK[BDSocialShareSDK registerApiKey:kBD_SOCIAL_SHARE_API_KEY andSupportPlatforms:platforms];
}
// import the baidu social share interface
#import <BaiduSocialShare/BDSocialShareSDK.h>// the key for API key
#define kBD_SOCIAL_SHARE_API_KEY @"SzxPfPb1dw9WcFzdEE8u7can"@interface ExampleViewController ()@end@implementation ExampleViewController- (void)viewDidLoad
{[super viewDidLoad];[self initializeBaiduSocialSDK];// Do any additional setup after loading the view, typically from a nib.
}- (void)initializeBaiduSocialSDK
{// decleare the platforms to shareNSArray *platforms = [NSArray arrayWithObjects:kBD_SOCIAL_SHARE_PLATFORM_SINAWEIBO,kBD_SOCIAL_SHARE_PLATFORM_QQWEIBO,kBD_SOCIAL_SHARE_PLATFORM_QQZONE,kBD_SOCIAL_SHARE_PLATFORM_KAIXIN,nil];// initialize baidu share SDK[BDSocialShareSDK registerApiKey:kBD_SOCIAL_SHARE_API_KEY andSupportPlatforms:platforms];
}//
// receive the button click event
//
- (IBAction)onShareOutButtonClicked:(id)sender
{// create the share contentNSString *title = @"想休息啊";NSString *message = @"今天北京的天气真好,好想出去郊游哇";NSString *url = @"http://www.baidu.com";BDSocialShareContent *content = [BDSocialShareContent shareContentWithDescription:message url:url title:title];// start to share[BDSocialShareSDK showShareMenuWithShareContent:content menuStyle:BD_SOCIAL_SHARE_MENU_THEME_STYLEresult:^(SHARE_RESULT requestResult, NSString *shareType, id response, NSError *error) {if (requestResult == BD_SOCIAL_SHARE_SUCCESS) {//分享成功的处理} else if (requestResult == BD_SOCIAL_SHARE_CANCEL){//用户取消分享的处理} else if (requestResult == BD_SOCIAL_SHARE_FAIL){//分享发生错误的处理}}];}- (void)didReceiveMemoryWarning
{[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}
@end
10.在UI添加一个Button,并将此Button的点击事件与定义好的事件处理函数相连
- 程序运行后,点击Share Out按钮,弹出平台界面:
- 点击新浪,并登陆,弹出分享页面,点击分享按钮进行分享:
这篇关于社会化分享 SDK的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!