我正在使用 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");
该对象在与上述代码相关的 .h 文件中flickrRequest
定义和定义。@property
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 的文档,“error 2147418115
”被定义为“ OFFlickrAPIRequestFaultyXMLResponseError
”。我不太确定这意味着什么。也很奇怪——当我只尝试上传一张照片时,“成功”出现了四次。
使用 ObjectiveFlickr 的示例应用程序“Snap and Run”可以在我正在测试的同一设备上正常上传照片。比较我的应用程序和 Snap and Run 之间的代码,我没有发现任何可能导致照片无法上传的重大差异。
任何帮助将不胜感激。