风和日丽,艳阳高照,小组长见我怡然自得不亦乐乎的样子,便想着给我找点活儿干,于是乎,"灵光"一现遍让我做FaceBook分享,瞬间我就一脸懵,内心无限画圈圈,抱怨完活儿还得干。。。
FaceBookSDK挺友好的,SDK也很好集成,文档写的也很详细,没有什么大坑,一步一步的做就好了。
1.找到梯子,毕竟要求外面的世界。
2.下载SDK的链接,打开FaceBook分享SDK集成网站
3.开始集成,
a.导入需要的库
b.用下面方式打开info.plist
c.在最末尾但是在最后的《/dict》和《/plist》之前添加
【注:App编号和App名字自己注册成为开发者之后创建一个应用就出现了】
d.编码部分
Appdelegate.m
头部导入#import《FBSDKCoreKit/FBSDKCoreKit.h》
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (BOOL)application:(UIApplication*)application
openURL:(NSURL*)url
options:(NSDictionary *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
// Add any custom logic here.
returnhandled;
}
- (void)applicationDidBecomeActive:(UIApplication*)application {
[FBSDKAppEvents activateApp];
}
在需要引用分享的地方
引入头文件#import《FBSDKShareKit/FBSDKShareLinkContent.h》
//分享链接
FBSDKShareLinkContent*linkContent = [[FBSDKShareLinkContent alloc]init];
linkContent.contentURL= [NSURL URLWithString:@"https://www.baidu.com"];
//分享图片
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = image; photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
//分享视频
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoURL = videoURL;
FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init];
content.video = video;
//混合分享
FBSDKSharePhoto *photo = [FBSDKSharePhoto photoWith...
FBSDKShareVideo *video = [FBSDKShareVideo videoWith...
FBSDKShareMediaContent *content = [FBSDKShareMediaContent new];
content.media = @[photo, video];
【注:分享不同类型,注意导入不同的头文件】
如果没有UI的话,也可以使用FaceBook最经典的分享按钮
引入头文件#import《FBSDKShareKit/FBSDKShareButton.h》
//自带分享
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"https://www.baidu.com"];
FBSDKShareButton *button = [[FBSDKShareButton alloc] init];
CGRectfram = button.frame;
button.frame = CGRectMake(100,100,fram.size.width,fram.size.height);
button.shareContent= content;
[self.viewaddSubview:button];
也可以自定义button上的字等等操作,和正常操作button一样
好了,测试一下,没什么问题,可以交差去了,✌️
菜鸟走向大牛,大家共同前进,如果觉得不错,请给个赞/关注。
一起交流学习,有问题随时欢迎联系,邮箱:383708669@qq.com