简体   繁体   English

如何在您的应用程序中截取屏幕截图并将其发布到 facebook?

[英]How to take a screenshot in your App and publish it on facebook?

I'm trying to use facebook within my App by posting a screenshot of my App on my wall.我正在尝试通过在我的墙上发布我的应用程序的屏幕截图来在我的应用程序中使用 facebook。

I already made the functions for taking a screenshot我已经做了截图功能

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

            UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

and for posting stuff on my facebook wall with an icon, title and small description.并在我的 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//\"}]"; 
}

Any suggestions of how to put my screenshot within the postToWall method?关于如何将我的屏幕截图放在 postToWall 方法中的任何建议? Thanks in advance!提前致谢!

It seems like you can't do this completely via Facebook.您似乎无法通过 Facebook 完全做到这一点。 You should look at photo sharing sites for this.您应该为此查看照片共享网站。 First upload your image to that site and get the link.首先将您的图像上传到该站点并获取链接。 Then share it via this method.然后通过这个方法分享。

Edit编辑
I am not saying the photo upload isn't possible.我并不是说照片上传是不可能的。 It just isn't possible to post a photo to the wall along with a link to your app without uploading it first.如果不先上传照片,就不可能将照片连同指向您的应用程序的链接一起发布到墙上。

Using Facebook's SDK for iPhone, it is possible.使用适用于 iPhone 的 Facebook 的 SDK 是可能的。 You will need to construct and argument block (NSDictionary) and send that to the your validated Facebook session.您将需要构造和参数块(NSDictionary)并将其发送到经过验证的 Facebook session。

In the snippet here, "session" is of type Facebook * defined in Facebook.h of the SDK.在此处的代码段中,“会话”的类型为 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM