0

我正在使用以下方法将照片发布到 Facebook。它工作正常,但是图像设置如下: NSURL *url = [NSURL URLWithString:@"http://www.example.com/image.png"];

我想让用户从他们的 iPhone 相机文件夹中选择图像。我将如何执行此操作 - 从相册中检索图像并通过此方法发送?

谢谢你的帮助

- (void)apiGraphUserPhotosPost {
    [self showActivityIndicator];
    currentAPICall = kAPIGraphUserPhotosPost;
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    // Download a sample photo
    NSURL *url = [NSURL URLWithString:@"http://www.example.com/image.png"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *img  = [[UIImage alloc] initWithData:data];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   img, @"picture",
                                   nil];
    [img release];

    [[delegate facebook] requestWithGraphPath:@"me/photos"
                          andParams:params
                      andHttpMethod:@"POST"
                        andDelegate:self];
}
4

2 回答 2

1

为此,您应该使用UIImagePickerController. 在此处查看 Apple 文档:

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

PS:对于非URL-[NSData dataWithContentsOfURL:]来说不是一个好主意。file:它是同步的。而是使用异步 API,例如-[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]

于 2012-05-24T11:04:08.343 回答
1

如果您已完成从图库中选择图像?

if not then please follow the steps here in this blog entry, once you got the image, then simply do this way:

UIImage *img  = yourImageFromLibrary;
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   img, @"picture",
                                   nil];
... //rest of code
于 2012-05-24T11:05:41.400 回答