一、去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三种分享方式的更多相关文章

  1. JavaScript 闭包的详细分享(三种创建方式)(附小实例)

    JavaScript闭包的详细理解 一.原理:闭包函数--指有权访问私有函数里面的变量和对象还有方法等:通俗的讲就是突破私有函数的作用域,让函数外面能够使用函数里面的变量及方法. 1.第一种创建方式 ...

  2. 通过三个DEMO学会SignalR的三种实现方式

    一.理解SignalR ASP .NET SignalR 是一个ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时通信(即:客户端(Web页面)和服务器端可以互相实时的通知消息 ...

  3. 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 ...

  4. v-bind绑定属性样式——class的三种绑定方式

    1.布尔值的绑定方式 <div id="demo"> <span v-bind:class="{‘class-a‘:isA ,‘class-b‘:isB ...

  5. 通过三个DEMO学会SignalR的三种实现方式 转载https://www.cnblogs.com/zuowj/p/5674615.html

    一.理解SignalR ASP .NET SignalR 是一个ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时通信(即:客户端(Web页面)和服务器端可以互相实时的通知消息 ...

  6. Hive metastore三种配置方式

    http://blog.csdn.net/reesun/article/details/8556078 Hive的meta数据支持以下三种存储方式,其中两种属于本地存储,一种为远端存储.远端存储比较适 ...

  7. django 模板语法和三种返回方式

    模板 for循环 {% for athlete in athlete_list %} <li>{{ athlete.name }}</li> {% endfor %} if语句 ...

  8. js的三种继承方式及其优缺点

    [转] 第一种,prototype的方式: //父类 function person(){ this.hair = 'black'; this.eye = 'black'; this.skin = ' ...

  9. spring ioc三种注入方式

    spring ioc三种注入方式 IOC ,全称 (Inverse Of Control) ,中文意思为:控制反转 什么是控制反转? 控制反转是一种将组件依赖关系的创建和管理置于程序外部的技术. 由容 ...

随机推荐

  1. Chrome离线下载地址

    每当chrome有更新之后,都有不少用户想要下载离线版的安装文件,但苦于找不到下载地址而发愁,其实这个问题很简单,下面我来分享一下方法(仅针对Windows操作系统): 对于稳定版(正式版)Chrom ...

  2. 已跳过 'cache' -- 节点处于冲突状态

    svn resolved ./cache ./cache 为冲突文件路径“cache”的冲突状态已解决

  3. MVC controller and View

    actionresult,jsonresult redirectresult partialview, viewdata, tempdata filter viewdata,只能在当前action中有 ...

  4. 数据库随机取n条记录

    SQL Server SELECT TOP N  *  FROM  表名  ORDER BY  NEWID() My SQL  SELECT  *  FROM  表名 ORDER BY RAND() ...

  5. [JS]学习Javascript闭包(Closure)

    转自:阮一峰 闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 下面就是我的学习笔记,对于Javascript初学者应该是很有用的. 一.变量的 ...

  6. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  7. mrp功能分类

    mrp主要有六大功能子系统:[工程管理子系统].[销售管理子系统].[计划管理子系统].[采购管理子系统].[库存管理子系统].[MRP运行管理子系统].[工程管理子系统]主要功能:产品/物料编码表. ...

  8. jQuery图片延迟加载插件jQuery.lazyload

      插件描述:jQuery图片延迟加载插件jQuery.lazyload,使用延迟加载在可提高网页下载速度.在某些情况下,它也能帮助减轻服务器负载. 使用方法 引用jquery和jquery.lazy ...

  9. Python进阶08 异常处理

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 本文特别感谢kylinfish的纠正,相关讨论见留言区. 异常处理 在项目开发中, ...

  10. 根据职位名,自动生成jd

    代码本身就是最好的解释,不赘述. 文本聚类输出: cluster.py #!/usr/bin/env python # coding=utf-8 import jieba,re from gensim ...