我试图通过在我的墙上张贴我的应用程序的屏幕截图来在我的应用程序中使用 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/