在Facebook上分享截图 [英] Share screenshot on Facebook

查看:225
本文介绍了在Facebook上分享截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在iPhone上截取屏幕截图并将其保存到相册中。我想要的是一个分享按钮,自动发送此屏幕截图和Facebook。有没有人有任何想法如何实现?

I am using the following code to take a screenshot on my iPhone and save it to the photo album. What I would like is a share button to automatically send this screenshot and to Facebook. Does anyone have any ideas how to implement?

- (UIImage*)captureView:(UIView *)view
{
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}

- (void)saveScreenshotToPhotosAlbum:(UIView *)view
{
UIImageWriteToSavedPhotosAlbum([self captureView:self.view], nil, nil, nil);
}

- (void)viewDidLoad
{
[super viewDidLoad];
[self setUpData];

CGRect frame = self.view.bounds;
frame.size.height -= 90;

self.tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.tableView setDataSource:self];
[self.tableView setDelegate:self];

[self.view addSubview:self.tableView];

UIBarButtonItem *shareBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(saveScreenshotToPhotosAlbum:)];
[self.navigationItem setRightBarButtonItem:shareBtn];

}


推荐答案

嗯,你可以使用iOS6内置的Facebook集成。
包含社交 framwork在构建阶段
代码看起来应该类似于此剪辑:

Well, you can use the iOS6 built-in Facebook integration. Include the Social framwork in Build Phases The code should look bi similar to this snipped:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){
    mySLComposerSheet = [[SLComposeViewController alloc] init];
    mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [mySLComposerSheet setInitialText:@"Some Text"];
    [mySLComposerSheet addImage:[self captureView:self.view]];
    [self presentViewController:mySLComposerSheet animated:YES completion:nil];
}

*请注意,这不会自动共享屏幕截图,但它会附加它到Facebook撰写表,如果他/她想要,用户可以发布。要自动执行此操作,您需要进行更深入的Facebook集成,并且用户应该允许您的应用程序在他/她的墙上发布。如果项目部署目标 c ,那么应该使用 Social 框架或 ShareKit 来完成code>低于iOS 6.0

*Note this will not "automatically" share the screenshot but it will attach it to a Facebook Compose Sheet and the user can post it if he/she wants to. To do it automatically, you will need to do a deeper Facebook integration and the user should give permission for your app to post on his/her wall. This again should be done with the Social framework or ShareKit if the project Deployment target is bellow iOS 6.0

这篇关于在Facebook上分享截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆