![](/img/trans.png)
[英]Posting image to FaceBook wall from iPhone camera roll with PhoneGap
[英]Post an image to Facebook from the iPhone camera library in iOS
我正在使用以下方法將照片發布到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];
}
為此,您應該使用UIImagePickerController
。 看看這里的Apple文檔:
PS: -[NSData dataWithContentsOfURL:]
對於非file:
URL不是一個好主意。 它是同步的。 而是使用異步API,如-[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
如果您已完成從圖庫中選擇圖像?
如果沒有,那么請按照此博客條目中的步驟,一旦獲得圖像,然后只需這樣做:
UIImage *img = yourImageFromLibrary;
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, @"picture",
nil];
... //rest of code
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.