NSURLErrorDomain error -1021

风格不统一 提交于 2019-12-09 01:53:56

问题


I'm developing an app were I integrated dropbox. Login is done properly also I'm able to create folder in dropBox. But when I try to load file I'm getting error

Following error I'm getting

error making request to /1/files_put/dropbox/Info.plist - Error
Domain=NSURLErrorDomain Code=-1021 "The operation couldn’t be
completed. (NSURLErrorDomain error -1021.)" UserInfo=0x6859bc0
{destinationPath=/Info.plist,
sourcePath=/Users/bcod/Library/Application Support/iPhone
Simulator/5.0/Applications/0E1EE43C-8F6B-40FA-8696-D3992DA2DCE5/DBRoulette.app/Info.plist}

I'm not getting this error when I'm creating folder.


回答1:


I had the same problem with iOS 5.0 on iPhone, but the iPhone 6.1 simulator worked without creating error messages.

I took a look into the DropboxSDK / DBRestClient.m, especially the last lines of uploadFile:toPath:fromPath:params and implemented a categorie 'ExBody' on DBRequest to add the connection:needNewBodyStream method:

#import "DBRequest+ExBody.h"

@implementation DBRequest (ExBody)

#pragma mark NSURLConnection delegate methods

- (NSInputStream *)connection:(NSURLConnection *)connection needNewBodyStream:(NSURLRequest *)req {

    NSString * sourcePath = [userInfo objectForKey:@"sourcePath"];
    NSLog(@"%@ needs newBodyStream!", sourcePath);
    return [NSInputStream inputStreamWithFileAtPath:sourcePath];
}

@end

This worked for me. The method is called on iOS5, not on iOS6!




回答2:


Error -1021 is a NSURLErrorRequestBodyStreamExhausted error.

According to the documentation you're missing a delegate method:

NSURLErrorRequestBodyStreamExhausted
Returned when a body stream is needed but the client does not provide one. This impacts clients on iOS that send a POST request using a body stream but do not implement the NSURLConnection delegate method connection:needNewBodyStream. Available in OS X v10.7 and later.



来源:https://stackoverflow.com/questions/16117275/nsurlerrordomain-error-1021

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!