用预定义文本打开Facebook应用程序进行分享

时间:2015-09-01 10:57:11

标签: ios objective-c facebook cocoa-touch

请看一下这段代码:

 var a = ["PG,PGR"]
     a= a[0].split(',');

通过此代码,我想打开设备上安装的Facebook应用程序,并在共享对话框中打开它,其中 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]; } 字符串用作要共享的预定义文本。但不幸的是,它所做的只是打开我的时间表。我究竟做错了什么?或者甚至可能吗?我找不到任何关于如何正确执行此操作的文档或教程。感谢

1 个答案:

答案 0 :(得分:1)

使用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];
相关问题