Facebook三种分享方式
一、去Facebook开发者中心注册APP,获取APP ID https://developers.facebook.com
二、导入 FBSDKCoreKit.Framework, FBSDKLoginKit.Framework, FBSDKShareKit.Framework
三、在info.plist 文件中加入 <key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb218334765200160</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string></string>
<key>FacebookDisplayName</key>
<string>AirPlane</string> <key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array> 四、设置bundle id五、AppDelegate中设置 #import <FBSDKCoreKit/FBSDKCoreKit.h> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
} - (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
} - (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
} 六、控制器中设置 #import "ViewController.h"
#import <FBSDKShareKit/FBSDKShareKit.h>
#import <Social/Social.h>
#import "UIToastUtil.h" @interface ViewController ()<FBSDKSharingDelegate>
@property (nonatomic, strong) SLComposeViewController *mySLComposerSheet;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} /** 首先调用facebook客户端 */
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self shareToFacebook];
} /** 有Facebook客户端 */
- (void)shareToFacebook{
FBSDKShareLinkContent *content1 = [[FBSDKShareLinkContent alloc] init];
content1.contentURL = [NSURL URLWithString:@"https://developers.facebook.com"];
content1.contentTitle=@"我就是分享"; // [FBSDKShareDialog showFromViewController:self withContent:content1 delegate:nil];
// [FBSDKMessageDialog showWithContent:content1 delegate:nil];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.delegate = self;
[dialog setShareContent:content1];
dialog.mode = FBSDKShareDialogModeNative;
[dialog show];
} #pragma mark -FBSHARE DELEGATE
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results{
NSLog(@"--->有Facebook客户端,成功分享!");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error{
NSLog(@"--->分享失败!, %@", error);
if(error==nil||[[NSNull null] isEqual:error]){
/** 没有facebook客户端,检查手机是否绑定账号 */
[self shareFacebook];
}
} - (void)sharerDidCancel:(id<FBSDKSharing>)sharer{
NSLog(@"--->取消分享!");
} - (void)shareFacebook{
if ([[[[UIDevice currentDevice] systemVersion] substringToIndex:] intValue]>=){
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){
self.mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// [self.mySLComposerSheet setInitialText:self.productDetailModel.productName];//产品名
// NSURL *imageUrl = [NSURL URLWithString:self.productDetailModel.primaryThumbimage];
// NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
// [self.mySLComposerSheet addImage:[UIImage imageWithData:imageData scale:1]];//产品图
[self.mySLComposerSheet addURL:[NSURL URLWithString:@"https://developers.facebook.com"]];//产品地址
[self presentViewController:self.mySLComposerSheet animated:YES completion:nil];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}else{ /** 没有安装客户端,并且手机也没有绑定账号,使用网页分享 */
[self shareWithWeb];
}
[self.mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = @"点击取消分享";
break;
case SLComposeViewControllerResultDone:
output = @"点击分享";
break;
default:
break;
}
if ((result = SLComposeViewControllerResultCancelled)) {
// [UIToastUtil showToast:self.view message:@"you have not install facebook app."];
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:MBLocalizedString(kFacebookMessage) message:output delegate:nil cancelButtonTitle:MBLocalizedString(kFacebookOK) otherButtonTitles:nil];
// [alert show];
}
}];
}
} /** 没有Facebook客户端,手机Facebook也没有绑定账号,使用网页分享 */
- (void)shareWithWeb{
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content1.contentURL = [NSURL URLWithString:@"https://developers.facebook.com"];
content1.contentTitle=@“这是分享"; FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.delegate = self;
[dialog setShareContent:content];
dialog.mode = FBSDKShareDialogModeWeb;
[dialog show];
}
Facebook三种分享方式的更多相关文章
- JavaScript 闭包的详细分享(三种创建方式)(附小实例)
JavaScript闭包的详细理解 一.原理:闭包函数--指有权访问私有函数里面的变量和对象还有方法等:通俗的讲就是突破私有函数的作用域,让函数外面能够使用函数里面的变量及方法. 1.第一种创建方式 ...
- 通过三个DEMO学会SignalR的三种实现方式
一.理解SignalR ASP .NET SignalR 是一个ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时通信(即:客户端(Web页面)和服务器端可以互相实时的通知消息 ...
- SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论 SignalR 简单示例 通过三个DEMO学会SignalR的三种实现方式 SignalR推送框架两个项目永久连接通讯使用 SignalR 集线器简单实例2 用SignalR创建实时永久长连接异步网络应用程序
SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论 异常汇总:http://www ...
- v-bind绑定属性样式——class的三种绑定方式
1.布尔值的绑定方式 <div id="demo"> <span v-bind:class="{‘class-a‘:isA ,‘class-b‘:isB ...
- 通过三个DEMO学会SignalR的三种实现方式 转载https://www.cnblogs.com/zuowj/p/5674615.html
一.理解SignalR ASP .NET SignalR 是一个ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时通信(即:客户端(Web页面)和服务器端可以互相实时的通知消息 ...
- Hive metastore三种配置方式
http://blog.csdn.net/reesun/article/details/8556078 Hive的meta数据支持以下三种存储方式,其中两种属于本地存储,一种为远端存储.远端存储比较适 ...
- django 模板语法和三种返回方式
模板 for循环 {% for athlete in athlete_list %} <li>{{ athlete.name }}</li> {% endfor %} if语句 ...
- js的三种继承方式及其优缺点
[转] 第一种,prototype的方式: //父类 function person(){ this.hair = 'black'; this.eye = 'black'; this.skin = ' ...
- spring ioc三种注入方式
spring ioc三种注入方式 IOC ,全称 (Inverse Of Control) ,中文意思为:控制反转 什么是控制反转? 控制反转是一种将组件依赖关系的创建和管理置于程序外部的技术. 由容 ...
随机推荐
- Windows蓝屏后产生的.dmp分析原因
Windows系统电脑出现蓝屏后都会自动重启,重启后电脑屏幕会提示蓝屏的相关信息,此时如果你没有来得及查看,你也可以进入windows7的“事件查看器”(位置为:控制面板--系统和安全--管理工具-- ...
- Page.User.Identity.Name获取不到结果
如果在IIS部署后Page.User.Identity.Name获取不到值,需要检查以下设置: 1.web.config设置<authentication mode="Windows& ...
- Codeforces Round #373 (Div. 2)A B
Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 这回做的好差啊,a想不到被hack的数据,b又没有想到正确的思维 = = [题目链 ...
- NeHe OpenGL教程 第三十九课:物理模拟
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- 第一个Flask Web
https://github.com/ethan-funny/head-first-flask iOS多线程技术方案 http://www.cnblogs.com/Erma-king/p/593427 ...
- svn 中 版本回退
譬如有个文件,有十个版本,假定版本号是1,2,3,4,5,6,7,8,9,10. Revert to this revision: 如果在版本6这里点击“Revert to this revision ...
- activity属性_ _activity 属性说明
activity是android中使用非常平凡的一种组件,我们除了需要掌握activity中的生命周期以外,还需要掌握activity中的其 他设置. 1.activity 中主题的设置 andr ...
- java位运算
Java的位运算(bitwise operators)直接对整数类型的位进行操作,这些整数类型包括long.int.short.char和 byte,位运算符具体如下表: 运算符 说明 << ...
- Eclipse Tomcat配置/管理/调试指南
从myeclipse转到Eclipse最不方便的之一莫过于Web项目部署了,老是在想怎么不能把myeclipse的那个移植过来,或者有没有高人能按照Myeclipse开发一个,非常遗憾. 原版的Ecl ...
- iOS8远程通知处理
// IOS8 新系统需要使用新的代码注册推送if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){ [[UI ...