使用 SLComposeViewController 在 Facebook 中分享图片
Share Image in Facebook using SLComposeViewController
我正在我的应用程序中实现 Facebook 共享。需要共享带有描述的图像,但是一旦点击或单击图像,它应该被导航到门户网站。
不过,使用提要对话框可以做到这一点,但我想使用社交框架来做到这一点。这可能吗 ?
使用这个
SLComposeViewController * fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(@"Cancelled.");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(@"Posted.");
}
break;
}};
[fbController addImage:[UIImage imageNamed:@"1.jpg"]];
[fbController setInitialText:@"Check out this article."];
[fbController addURL:[NSURL URLWithString:@"URLString"]];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled)
{
DebugLog(@"Cancelled");
}
else
{
[UIUtils alertView:NSLocalizedString(@"FB POST SUCCEEDED", nil) withTitle:NSLocalizedString(@"SUCCESS", nil)];
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
//Adding the Text to the facebook post value from iOS
[controller setInitialText:NSLocalizedString(@"SHARE TWITTER", nil)];
//Adding the URL to the facebook post value from iOS
// [controller addURL:[NSURL URLWithString:@"http://www.mobile.safilsunny.com"]];
//Adding the Image to the facebook post value from iOS
[controller addImage:self.crushCardImage];
[self.view.window.rootViewController presentViewController:controller animated:YES completion:Nil];
}
else
{
[UIUtils alertView:NSLocalizedString(@"NO FB", nil) withTitle:NSLocalizedString(@"FAILURE", nil)];
}
}
这种定制好像做不到啊。但是,要从本机框架实现所需的功能,网页 url 应包含以下 post.
中所述的元数据
how to use og meta tag for facebook share
使用 SLComposeViewController,您无法为用户预填充 Facebook post。这些方法存在于社交框架中,但几年前 Facebook 不允许应用程序这样做,所以即使你使用:
BOOL initialTextSet = [fbController setInitialText:@"Check out this article."];
该方法将 return 是,但实际上不会填充文本。
如果您想更好地控制您正在 post 的内容,那么您必须将 Facebook SDK 添加到您的项目中。我实际上在我的应用程序的早期版本中采用了这条路线,但维护起来很痛苦。最后,我只使用了 Apple 原生框架。它比 FB SDK 更容易使用,而且它是面向未来的。无需担心您的下一个 iOS 版本构建是否会突然破坏 Facebook 共享,因为 SDK 需要更新(而且经常更新)。
我正在我的应用程序中实现 Facebook 共享。需要共享带有描述的图像,但是一旦点击或单击图像,它应该被导航到门户网站。
不过,使用提要对话框可以做到这一点,但我想使用社交框架来做到这一点。这可能吗 ?
使用这个
SLComposeViewController * fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(@"Cancelled.");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(@"Posted.");
}
break;
}};
[fbController addImage:[UIImage imageNamed:@"1.jpg"]];
[fbController setInitialText:@"Check out this article."];
[fbController addURL:[NSURL URLWithString:@"URLString"]];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled)
{
DebugLog(@"Cancelled");
}
else
{
[UIUtils alertView:NSLocalizedString(@"FB POST SUCCEEDED", nil) withTitle:NSLocalizedString(@"SUCCESS", nil)];
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
//Adding the Text to the facebook post value from iOS
[controller setInitialText:NSLocalizedString(@"SHARE TWITTER", nil)];
//Adding the URL to the facebook post value from iOS
// [controller addURL:[NSURL URLWithString:@"http://www.mobile.safilsunny.com"]];
//Adding the Image to the facebook post value from iOS
[controller addImage:self.crushCardImage];
[self.view.window.rootViewController presentViewController:controller animated:YES completion:Nil];
}
else
{
[UIUtils alertView:NSLocalizedString(@"NO FB", nil) withTitle:NSLocalizedString(@"FAILURE", nil)];
}
}
这种定制好像做不到啊。但是,要从本机框架实现所需的功能,网页 url 应包含以下 post.
中所述的元数据how to use og meta tag for facebook share
使用 SLComposeViewController,您无法为用户预填充 Facebook post。这些方法存在于社交框架中,但几年前 Facebook 不允许应用程序这样做,所以即使你使用:
BOOL initialTextSet = [fbController setInitialText:@"Check out this article."];
该方法将 return 是,但实际上不会填充文本。
如果您想更好地控制您正在 post 的内容,那么您必须将 Facebook SDK 添加到您的项目中。我实际上在我的应用程序的早期版本中采用了这条路线,但维护起来很痛苦。最后,我只使用了 Apple 原生框架。它比 FB SDK 更容易使用,而且它是面向未来的。无需担心您的下一个 iOS 版本构建是否会突然破坏 Facebook 共享,因为 SDK 需要更新(而且经常更新)。