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) ,中文意思为:控制反转 什么是控制反转? 控制反转是一种将组件依赖关系的创建和管理置于程序外部的技术. 由容 ...
随机推荐
- NTFS文件系统简介(转载)
原文地址:http://www.cnblogs.com/watertao/archive/2011/11/28/2266595.html 1.简介 NTFS(New Technology File S ...
- 在编译oc中protocol时出现的错误
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang ...
- PDF内容不允许复制的解决方法!
PDF文档的内容不允许复制解决方法! PDF的加密有两个级别: 一个是Owner级别,就是打开文档时需要输入密码PDF Password Remover可以用来破解Owner级别的口令,但是不能用于破 ...
- webuploader在同一个页面支持多个按钮实例
之前在时候用到webuploader ,起初是支持单实例,后来要求支持多实例. webuploder API网址,如果不懂我说的可以去查看http://fex.baidu.com/webuploade ...
- ruby关于flip-flop理解上一个注意点
(..).each do |x| puts x ) .. (x == ) end 上面的flip-flop的用法,你可以理解成 将 大于等于5和小于等于10的数字打印出来,也就是理解成 puts x ...
- compass项目监控文件报 /usr/bin/env 找不到文件
1 找到ruby执行文件目录 $ wherris ruby ruby: /usr/lib/ruby /home/rudy/.rbenv/shims/ruby 2 设置软链接 sudo ln -s /h ...
- 鼎信通达gsm网关和asterisk对接的调试
设备型号:4gsm卡,型号是DWG2000C-4Egsm网关IP地址: 10.3.6.250asteriskIP地址: 10.3.6.251 1)首先在asterisk里面添加到gsm网关的中继,并做 ...
- [ActionScript] AS3解决html与flash鼠标滚轮冲突的问题
JS端: <script type="text/javascript"> <!-- var winWidth = 0; var winHeight = 0; va ...
- Servlet中的cookie和session
保存数据的2中方式 Cookie Session Cookie 我们可以将一些信息保存到cookie中,cookie存放在对应的浏览器目录里面.每个站点可以保存20个cookie,最大长度不超过4k. ...
- javaSE学习博客与笔记
equals和==的区别 Java中equals和==的区别 java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,do ...

五、AppDelegate中设置
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {