作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
请看这段代码:
NSString *text = [NSString stringWithFormat:@"%@",
[@"Hello world!" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *post = [NSString stringWithFormat:@"fb://publish/profile/me?text=%@", text];
NSURL* url = [NSURL URLWithString:post];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
通过这段代码,我想打开安装在设备上的 Facebook 应用程序,并在共享对话框中打开它,并将 text
字符串用作要共享的预定义文本。但不幸的是,它只是打开了我的时间线。我究竟做错了什么?甚至有可能吗?我找不到任何关于如何正确执行此操作的文档或教程。谢谢
最佳答案
使用 FacebookSDK 的框架有一个简单的方法。这只需要 2 分钟。
FBSDKCoreKit.framework
FBSDKShareKit.framework
如果您的设备中没有安装 facebook 应用程序,那么这将打开默认的网络浏览器。
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
//在 viewdidload 或其他地方
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = @"Scare Prank";
content.contentDescription = @"Someone just got Scare Pranked with ♫";
content.contentURL = [NSURL URLWithString:soundUrl];
content.imageURL = [NSURL URLWithString:@“some icon url”];
FBSDKShareButton *button = [[FBSDKShareButton alloc] initWithFrame:CGRectMake(0, 0, 200, 43)];
button.center = self.center;
button.shareContent = content;
[self addSubview:button];
关于ios - 打开带有预定义文本的 Facebook 应用程序以共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32329859/
我是一名优秀的程序员,十分优秀!