不使用第三方分享框架实现分享功能
来源:互联网 发布:马来西亚第二家园 知乎 编辑:程序博客网 时间:2024/05/17 23:10
在以前的项目中,实现分享功能需要先去申请下载友盟的社会化组件,里面的QQ分享还有微信分享还要区申请繁琐的key,容易出现各种麻烦,如果碰到友善的友盟客服,他会耐心的给你解答,要是碰到态度不好的,人家直接不鸟你(我就碰到这种情况,半天恢复我,而且态度不敢恭维)。现在使用苹果原生的social.framework也能实现简单的分享功能了。social.framework目前只能实现在Facebook、Twitter、新浪微博、腾讯微博等平台实现分享。在使用前需要导入social.framework框架,并且在具体的ViewController中导入头文件。下面是我自己的初步体验代码:
#import "ViewController.h"#import <Social/Social.h>@interface ViewController (){ //Facebook分享按钮 UIButton *faceBtn; //Twitter分享按钮 UIButton *twitterBtn; //新浪微博分享按钮 UIButton *sinaBtn; //腾讯微博分享按钮 UIButton *tenBtn;}@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; faceBtn=[[UIButton alloc]initWithFrame:CGRectMake(110, 100, 100, 44)]; [faceBtn setBackgroundColor:[UIColor blueColor]]; [faceBtn setTitle:@"faceBook" forState:UIControlStateNormal]; [faceBtn addTarget:self action:@selector(faceBtnClickedAction) forControlEvents:UIControlEventTouchUpInside]; twitterBtn=[[UIButton alloc]initWithFrame:CGRectMake(110, 200, 100, 44)]; [twitterBtn setBackgroundColor:[UIColor blueColor]]; [twitterBtn setTitle:@"twitter" forState:UIControlStateNormal]; [twitterBtn addTarget:self action:@selector(twitterBtnClickedAction) forControlEvents:UIControlEventTouchUpInside]; sinaBtn=[[UIButton alloc]initWithFrame:CGRectMake(110, 300, 100, 44)]; [sinaBtn setBackgroundColor:[UIColor blueColor]]; [sinaBtn setTitle:@"sina" forState:UIControlStateNormal]; [sinaBtn addTarget:self action:@selector(sinaBtnClickedAction) forControlEvents:UIControlEventTouchUpInside]; tenBtn=[[UIButton alloc]initWithFrame:CGRectMake(110, 400, 100, 44)]; [tenBtn setBackgroundColor:[UIColor blueColor]]; [tenBtn setTitle:@"ten" forState:UIControlStateNormal]; [tenBtn addTarget:self action:@selector(tenBtnClickedAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:faceBtn]; [self.view addSubview:twitterBtn]; [self.view addSubview:sinaBtn]; [self.view addSubview:tenBtn]; // Do any additional setup after loading the view, typically from a nib.}/** * 点击事件的实现方法 */#pragma mark---facebook按钮被点击-(void)faceBtnClickedAction{ NSLog(@"share use facebook"); //响应点击事件之前要先判断,用户对facebook的配置是否完成 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { //弹出框可以是系统默认的,也可以是自定义的[[SLComposeViewController alloc]initWithNibName:@"" bundle:nil] SLComposeViewController *compose=[[SLComposeViewController alloc]init]; compose=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //分享的文字 [compose setInitialText:@"我是天朝良民!\n"]; //分享的链接 [compose addURL:[NSURL URLWithString:@"http://www.mipow.com"]]; //分享的图片 [compose addImage:[UIImage imageNamed:@"app.png"]]; //界面跳转 [self presentViewController:compose animated:YES completion:^{ NSLog(@"facebook 分享成功"); }]; }else{ NSLog(@"请配置好你的Facebook"); }}#pragma mark---twitter按钮被点击-(void)twitterBtnClickedAction{ NSLog(@"share use twitter"); if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { SLComposeViewController *compose=[[SLComposeViewController alloc]init]; compose=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; //分享的文字 [compose setInitialText:@"天朝生活富足!\n"]; //分享的链接 //分享的图片 //界面跳转 [self presentViewController:compose animated:YES completion:^{ NSLog(@"twitter 分享成功"); }]; }else{ NSLog(@"请配置好你的twitter"); }}#pragma mark---sinaBtn按钮被点击-(void)sinaBtnClickedAction{ NSLog(@"share use sina"); if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) { SLComposeViewController *compose=[[SLComposeViewController alloc]init]; compose=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo]; //分享的文字 [compose setInitialText:@"天朝生活富足!\n"]; //分享的链接 //分享的图片 //界面跳转 [self presentViewController:compose animated:YES completion:^{ NSLog(@"sina weibo 分享成功"); }]; }else{ NSLog(@"请配置好你的sina weibo"); }}#pragma mark---tenBtn被点击-(void)tenBtnClickedAction{ NSLog(@"share use ten"); if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTencentWeibo]) { SLComposeViewController *compose=[[SLComposeViewController alloc]init]; compose=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTencentWeibo]; //分享的文字 [compose setInitialText:@"天朝生活富足!\n"]; //分享的链接 //分享的图片 //界面跳转 [self presentViewController:compose animated:YES completion:^{ NSLog(@"tencent weibo 分享成功"); }]; }else{ NSLog(@"请配置好你的tencent weibo"); }}
0 0
- 不使用第三方分享框架实现分享功能
- ShareSdk实现第三方分享功能
- 利用ShareSDK实现第三方分享功能
- 最新Android实现分享到QQ QZone 博客功能(集成官方SDK,不使用第三方)
- android一键分享功能不使用任何第三方sdk
- android一键分享功能不使用任何第三方sdk
- android一键分享功能不使用任何第三方sdk
- Android:QQ分享、微信分享、朋友圈分享(不使用第三方SDK)
- Android:QQ分享、微信分享、朋友圈分享(不使用第三方SDK)
- Android:QQ分享、微信分享、朋友圈分享(不使用第三方SDK)
- 通过使用第三方SDK来实现应用的分享,第三方登陆,数据信息统计等功能(ShareSDK)。
- android 实现QQ第三方登录,分享功能
- 友盟第三方 登录与分享功能实现
- 【第三方SDK】使用ShareSDK实现新浪微博的一键分享功能
- 【Android进阶】使用第三方平台 ShareSDK 实现新浪微博的一键分享功能
- 使用第三方平台 ShareSDK 实现新浪微博的一键分享功能
- 【Android进阶】使用第三方平台 ShareSDK 实现新浪微博的一键分享功能
- 【Android进阶】使用第三方平台 ShareSDK 实现新浪微博的一键分享功能
- 用Redis存储Tomcat集群的Session
- Cocos2d-X3.0bate_关于一些“无法解析的外部符号”的配置问题解决方法
- C#与C/C++的交互
- JavaWeb中读取文件资源的路径问题
- struts2往action传值时的乱码问题
- 不使用第三方分享框架实现分享功能
- P2P技术
- Android Studio系列-签名打包
- Oozie工作流程定义详解
- ERP知识点(1)软件功能
- 分布式网络爬虫架构-技术选型
- iOS中定时器NSTimer使用
- svn commit failed: Could not use external editor to fetch log message
- python 发送邮件