我正在使用 ObjectiveFlickr 库将照片从我的 iPhone 应用程序上传到 Flickr。我可以授权该应用程序并执行一般请求,但在尝试上传照片时遇到错误。要上传的照片是使用 AVFoundation 捕获的图像。这是相关代码:
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");
The flickrRequest
对象被定义并且@property
位于与上述代码相关的 .h 文件中。
The 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 and Run 之间的代码,我没有发现任何可能导致照片无法上传的重大差异。
任何帮助将不胜感激。