iphone - 如何在您的 App 中截取屏幕截图并发布到 facebook 上?

标签 iphone image facebook uiimage screenshot

我试图通过在我的墙上张贴我的应用程序的屏幕截图来在我的应用程序中使用 facebook。

截图的功能我已经做了

UIGraphicsBeginImageContext(self.view.bounds.size);
            [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
            UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();

            UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

并用于在我的 Facebook 墙上发布带有图标、标题和简短描述的内容。

- (void)postToWall {


    FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
    dialog.userMessagePrompt = @"Enter your message:";
    dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@ share's a photo\",\"href\":\"mywebsite.com/\",\"caption\":\"%@thinks this is a nice photo\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"mywebsite.com/icon.png\",\"href\":\"mywebsite.com/\"}]}",
                         _facebookName, _facebookName];

    dialog.actionLinks = @"[{\"text\":\"Get My App\",\"href\":\"http://itunes.apple.com//\"}]"; 
}

关于如何将我的屏幕截图放在 postToWall 方法中的任何建议?提前致谢!

最佳答案

使用 Facebook 的 iPhone SDK,这是可能的。您将需要构建和论证 block (NSDictionary) 并将其发送到您经过验证的 Facebook session 。

在此处的代码片段中,“session”是 Facebook * 类型,在 SDK 的 Facebook.h 中定义。

NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:captionText forKey:@"caption"];
[args setObject:messageText forKey:@"message"];
[args setObject:UIImageJPEGRepresentation(yourImage, 0.7) forKey:@"picture"];

[session requestWithMethodName:@"photos.upload" andParams:args ndHttpMethod:@"POST" andDelegate:self];

关于iphone - 如何在您的 App 中截取屏幕截图并发布到 facebook 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6253381/

相关文章:

java - 滑动查看图像阵列中的下一张图片

android - 如何在 Android 内置图库中打开外部图像(来自网络)

mysql - 安全存储图像,Ubuntu 上的数据库与加密。

iphone - 在 iPhone 上,响应 UDP 数据的 send() 时,EPERM (errno == 1) 是什么意思?

iphone - 带有 [NSString stringWithFormat :] appears as "(null)" 的 Nil 字符串

ios - 在 Swift 中进行应用内购买后,广告不会被删除

java - 用户注册与 Facebook 连接

node.js - passportjs facebook 将请求传递给回调

ios - 如何使用用户名链接到 iOS 应用程序中的 Facebook 用户?

ios - 如果 Watch 应用程序在 iPhone 应用程序运行之前打开,则不会填充任何数据