4

我正在尝试使用 iOS6 Facebook 功能将屏幕截图从我的应用程序导出到 Facebook。按下按钮时如何显示应用程序内的选项?

以下是我当前的代码。我想截取屏幕截图,同时使用 iOS6 Facebook 功能导出到 Facebook。

- (IBAction)export1:(id)sender{

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath
                      atScrollPosition:UITableViewScrollPositionTop
                              animated:YES];
exporting.hidden=YES;

CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);

else
    UIGraphicsBeginImageContext(imageSize);

CGContextRef context = UIGraphicsGetCurrentContext();

// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows]) 
{
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
    {
        // -renderInContext: renders in the coordinate space of the layer,
        // so we must first apply the layer's geometry to the graphics context
        CGContextSaveGState(context);
        // Center the context around the window's anchor point
        CGContextTranslateCTM(context, [window center].x, [window center].y);
        // Apply the window's transform about the anchor point
        CGContextConcatCTM(context, [window transform]);
        // Offset by the portion of the bounds left of and above the anchor point
        CGContextTranslateCTM(context,
                              -[window bounds].size.width * [[window layer] anchorPoint].x,
                              -[window bounds].size.height * [[window layer] anchorPoint].y);

        // Render the layer hierarchy to the current context
        [[window layer] renderInContext:context];

        // Restore the context
        CGContextRestoreGState(context);
    }
}

// Retrieve the screenshot image
CGRect contentRectToCrop = CGRectMake(0, 70, 740, 740);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], contentRectToCrop);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(croppedImage, nil, nil, nil);
4

3 回答 3

2

是使用 iOS6 中内置的 Facebook SDK 轻松将图像发布到 Facebook 的方法。如果这对您有任何帮助,我们会很高兴。快乐编码:)

于 2012-10-31T10:41:22.313 回答
2

Apple Developer Site 提供了一个新的 Social.framework,用于集成 Twitter 和 Facebook 等社交体验。

参考这里

于 2012-11-07T11:33:20.837 回答
1

@Clarence 我认为您应该查看适用于 iOS 的最新 Facebook SDK

它还有一些关于如何在 iOS 6 中在 facebook 上发布图像的教程。

只需下载 SDK,您就会在 Documents 文件夹中找到示例代码,其中包括一个示例 HelloFacebookSample,它显示了如何在 iOS 6 中在 Facebook 上发布图像。

你只需要在这个方法中传递你的图像对象 -

[FBNativeDialogs presentShareDialogModallyFrom:self initialText:nil image:croppedImage url:nil handler:nil];

在使用上述方法之前,您需要在此处正确遵循 v 3.1 安装说明

于 2012-10-29T17:01:57.323 回答