分享屏幕截图到Facebook

时间:2014-03-04 03:59:03

标签: ios facebook screenshot posting

我有以下代码发布到Facebook上我的应用程序;

这是.h文件

#import <UIKit/UIKit.h>
#import <Social/Social.h>
#import <Accounts/Accounts.h>

@interface LifeTipsViewController : UIViewController {
    SLComposeViewController *mySLComposerSheet;
}

  -(IBAction)PostToFacebook:(id)sender;

@end

和.m文件(Facebook发布代码)

-(IBAction)PostToFacebook:(id)sender {
    mySLComposerSheet = [[SLComposeViewController alloc] init];
    mySLComposerSheet = [SLComposeViewController
    composeViewControllerForServiceType:SLServiceTypeFacebook];
    [mySLComposerSheet setInitialText:@"hi"];
    [self presentViewController:mySLComposerSheet animated:YES completion:NULL];
}

我希望能够按下“分享”按钮和应用程序以获取当前视图的屏幕截图以发布到Facebook。需要将哪些代码添加到此Facebook发布代码中以允许它共享应用程序的屏幕截图? 这甚至可能吗?

提前致谢。

1 个答案:

答案 0 :(得分:2)

像这样。

-(IBAction)PostToFacebook:(id)sender {
    mySLComposerSheet = [[SLComposeViewController alloc] init];
    mySLComposerSheet = [SLComposeViewController
    composeViewControllerForServiceType:SLServiceTypeFacebook];
    [mySLComposerSheet setInitialText:@"hi"];


    UIGraphicsBeginImageContext(self.window.bounds.size);
    [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    [mySLComposerSheet addImage:image];


    [self presentViewController:mySLComposerSheet animated:YES completion:NULL];
}