一、去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. golang一个深复制的库

    https://github.com/mitchellh/copystructure

  2. ubuntu eclipse下配置C++ 环境

    首先你通过以下3个命令确定已安装好eclipse cdt sudo apt-get install eclipse sudo apt-get install eclipse-pde sudo apt- ...

  3. Android流量统计TrafficStats类

    对于Android流量统计来说在2.2版中新加入了TrafficStats类可以轻松获取,其实本身TrafficStats类也是读取Linux提供的文件对象系统类型的文本进行解析. android.n ...

  4. 基于List集合映射

    1. 实体类中使用List集合 public class Grade { private int id; private String name; private List<Student> ...

  5. ADF_ADF Faces系列2_使用JSF开发基于Ajax的用户界面:ADF Faces富客户端组件简介(Part2)

    2013-05-01 Created By BaoXinjian

  6. POJ 1740 A New Stone Game(普通博弈)

    A New Stone Game 题意: 对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆.最后谁无子可取即输 ...

  7. [实变函数]5.6 Lebesgue 积分的几何意义 $\bullet$ Fubini 定理

    1 本节推广数学分析中的 Fubini 定理. 为此, 先引入 (1)(从低到高) 对 $A\subset \bbR^p, B\subset\bbR^q$, $$\bex A\times B=\sed ...

  8. 防篡改php文件校验程序

    <?php /** * 校验线上源文件是否和本地的一致 * User: Administrator * Date: 2015/11/26 * Time: 9:30 */ include_once ...

  9. MySQL的时间进位问题

    mysql更新到5.6.4 之后 , 新增了一个叫factional seconds的特性 , 可以记录时间的毫秒值. 但是目前的数据库是不记录毫秒值的 , 所以会产生一个java中时间的Millis ...

  10. 无状态服务(stateless service)

    一.定义 无状态服务(stateless service)对单次请求的处理,不依赖其他请求,也就是说,处理一次请求所需的全部信息,要么都包含在这个请求里,要么可以从外部获取到(比如说数据库),服务器本 ...