我正在使用ObjectiveFlickr庫從我的iPhone應用上傳照片到Flickr。我可以授權應用程序並執行一般請求,但在嘗試上傳照片時出現錯誤。該照片是上傳的是使用AVFoundation拍攝的圖像。下面是相關的代碼:ObjectiveFlickr圖片上傳錯誤
UIImage *image = [[UIImage alloc] initWithData:imageData];
if ([[AppDelegate sharedDelegate].apiContext.OAuthToken length]) {
NSData *uploadData = UIImageJPEGRepresentation(image, 1);
if (!flickrRequest) {
flickrRequest = [[OFFlickrAPIRequest alloc] initWithAPIContext:[AppDelegate sharedDelegate].apiContext];
flickrRequest.delegate = self;
flickrRequest.requestTimeoutInterval = 60.0;
}
[flickrRequest uploadImageStream:[NSInputStream inputStreamWithData:uploadData] suggestedFilename:@"Test" MIMEType:@"image/jpeg" arguments:[NSDictionary dictionaryWithObjectsAndKeys:@"0", @"is_public", nil]];
[UIApplication sharedApplication].idleTimerDisabled = YES;
NSLog(@"Can upload photo");
的flickrRequest
對象被定義和@property
倒是在有關上述代碼.h文件。
的OFFlickrRequestDelegate
方法如下:
- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest imageUploadSentBytes:(NSUInteger)inSentBytes totalBytes:(NSUInteger)inTotalBytes {
NSLog(@"Success");
}
- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary {
NSLog(@"%s %@ %@", __PRETTY_FUNCTION__, inRequest.sessionInfo, inResponseDictionary);
}
- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didFailWithError:(NSError *)inError {
NSLog(@"%s %@ %@", __PRETTY_FUNCTION__, inRequest.sessionInfo, inError);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[inError description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
當我在設備上運行該項目的控制檯顯示:
Can upload photo
Success
Success
Success
Success
flickrAPIRequest:didFailWithError:(null) Error Domain=org.lukhnos.ObjectiveFlickr Code=2147418115 "The operation couldn’t be completed. (org.lukhnos.ObjectiveFlickr error 2147418115.)"
通過API的文檔,「錯誤2147418115
」搜索定義爲「OFFlickrAPIRequestFaultyXMLResponseError
」。我不確定這意味着什麼。也很奇怪 - 當我只是試圖上傳一張照片時,「成功」出現四次。
利用ObjectiveFlickr「Snap and Run」的示例應用程序可以在我正在測試的同一設備上上傳照片。比較我的應用程序和Snap和Run之間的代碼,我沒有看到可能導致照片無法上傳的任何主要差異。
任何幫助將不勝感激。