本文介绍了ObjectiveFlickr照片上传错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ObjectiveFlickr库从我的iPhone应用程序上传照片到Flickr。我可以授权应用程序并执行一般请求,但我在尝试上传照片时收到错误消息。要上传的照片是使用AVFoundation拍摄的图像。以下是相关代码:

I'm working on using the ObjectiveFlickr library to upload photos to Flickr from my iPhone app. I am able to authorize the app and perform general requests, but I am getting an error while trying to upload a photo. The photo is meant to be uploaded is an image captured using AVFoundation. Here is the relevant code:

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 'd。在.h文件中与上述代码有关。

The flickrRequest object is defined and @property'd in the .h file pertaining to the code above.

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];
}

当我在设备上运行项目时,控制台显示:

When I run the project on the device the console shows:

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 。我不太确定这意味着什么。同样奇怪 - 当我只是尝试上传一张照片时,成功出现了四次。

Searching through the API's documentation, "error 2147418115" is defined as "OFFlickrAPIRequestFaultyXMLResponseError". I'm not really sure what this means though. Also strange--"Success" appears four times when I'm only attempting to upload one photo.

使用ObjectiveFlickr的示例应用程序,快照并运行上传照片在我正在测试的同一台设备上。比较我的应用程序与Snap和Run之间的代码,我没有看到任何可能导致照片无法上传的重大差异。

The sample app utilizing ObjectiveFlickr, "Snap and Run" uploads photos fine on the same device that I am testing on. Comparing the code between my app and Snap and Run, I don't see any major differences that could cause the photo not to upload.

非常感谢任何帮助。

推荐答案

这很奇怪。 OFFlickrAPIRequestFaultyXMLResponseError 表示无法将返回的数据解析为XML。如果示例应用程序SnapAndRun正确运行而你的没有,我建议在ObjectiveFlickr.m中添加一行,就在行 NSString * stat = [rsp objectForKey:@stat]之后;

That is strange. OFFlickrAPIRequestFaultyXMLResponseError means the returned data cannot be parsed as XML. If the sample app SnapAndRun runs correctly and yours don't, I suggest add one line in ObjectiveFlickr.m, right after the line NSString *stat = [rsp objectForKey:@"stat"];:

NSString *dataString = [[[NSString alloc] initWithData:[request receivedData] encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"received response: %@", dataString);

这可以帮助您找出问题所在(例如,如果它是服务器端问题,或者某些问题)库遗漏的响应格式。)

This may help you find out what goes wrong (e.g. if it's a server-side issue, or some response format that the library missed).

这篇关于ObjectiveFlickr照片上传错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 19:54