Share screenshot on Facebook

喜欢而已 提交于 2019-12-06 13:37:17

问题


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];

}

回答1:


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];
}

*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



来源:https://stackoverflow.com/questions/16241377/share-screenshot-on-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!