访问Dropbox核心API错误信息iOS 8 Xcode

访问Dropbox核心API错误信息iOS 8 Xcode,ios,objective-c,dropbox-api,Ios,Objective C,Dropbox Api,此应用程序使用Dropbox核心API将文件移动到Dropbox以进行备份存储。上传和下载过程运行良好。代理调用正确,并允许我在上传和下载过程成功时验证它们。但是,当上传失败时,我无法以编程方式访问错误信息 例如,如果我删除了要上载的文件,那么这段代码a delegate方法将生成以下控制台信息,其中包括我想要的数据-我只是无法通过编程方式获取它 -(void)restClient:(DBrestClient *)client uploadFileFailedWithError:(NSError

此应用程序使用Dropbox核心API将文件移动到Dropbox以进行备份存储。上传和下载过程运行良好。代理调用正确,并允许我在上传和下载过程成功时验证它们。但是,当上传失败时,我无法以编程方式访问错误信息

例如,如果我删除了要上载的文件,那么这段代码a delegate方法将生成以下控制台信息,其中包括我想要的数据-我只是无法通过编程方式获取它

-(void)restClient:(DBrestClient *)client uploadFileFailedWithError:(NSError *)error {
NSLog(@"File upload failed with error: %@,error);
NSLog(@"error data: %@", [error.userInfo objectForKey:@"sourcePath"]);
}
2014-12-03 20:33:03.178生物日志[43089:4749399][警告]DropboxSDK: 文件不存在 /路径/文档/BiopBak123.sqlite-shm

2014-12-03 20:33:03.297 BiopLog[43089:4749399] File upload failed with
error: Error Domain=dropbox.com Code=1001 "The operation couldn’t be
completed. (dropbox.com error 1001.)" UserInfo=0x7fa9e2f814f0
{sourcePath=/path/Documents/BiopBak123.sqlite-shm, 
destinationPath=/BiopBak123.sqlite-shm

我决定通过解析错误数据来艰难地完成这项工作。在本例中,我的代码创建文件名,并且我始终在文件名中使用相同的基和相同的字符数。这是可行的,但我还是想知道更优雅的方法

- (void)restClient:(DBRestClient *)client uploadFileFailedWithError:(NSError *)error {

    //parse the error data for the file name
    NSString *fullErrorData = [NSString stringWithFormat:@"%@",error];
    NSString *answer;
    NSString *message;

    if ([fullErrorData containsString:@"FileBase"]) {
        NSRange range = [fullErrorData rangeOfString:@"FileBase"];
        NSRange newRange = {range.location,21};//the known length
        answer = [fullErrorData substringWithRange:newRange];

        message = [NSString stringWithFormat: @"The upload for file %@ failed. The remnants will be automatically deleted. You may receive an error message about the deletion - dismiss it.", answer];
    } else {
        message = @"Could not determine the file upload that failed.";
    }

    UIAlertView *uploadAlert = [[UIAlertView alloc]initWithTitle:@"Upload Failure" message:message delegate:nil cancelButtonTitle:@"Understood" otherButtonTitles: nil];

    [uploadAlert show];

    //Add code to clear any remnants

}//restClient:uploadFileFailedWithError

你的NSLog@error数据:。。。看起来不错。它以什么方式失败?它没有失败。我只需要能够提取文件名,与预期结果列表进行比较。显然,我可以尝试解析整个错误消息,但这似乎相当尼安德特人。我必须相信有一种方法可以调用sourcePath——我尝试了很多很多猜测,但都没有做到。就完整性而言,这对于成功方法来说很容易。那么,当你的NSLog@error数据:。。。线路在运行吗?你引用的日志似乎只显示了之前的行。哇。我的错误。我一定是把它从帖子上删掉了。2014-12-03 20:33:03.297生物日志[43089:4749399]错误数据:错误域=dropbox.com代码=1001操作无法完成。dropbox.com错误1001。UserInfo=0x7fa9e2f814f0{sourcePath=/path/Documents/BiopBak123.sqlite-shm,destinationPath=/BiopBak123.sqlite-shm}奇怪的是,我刚刚从你的问题中尝试了你的代码,在修复了DBrestClient->DBrestClient并在第一个NSLog中添加了缺失的代码之后,它对我来说像预期的那样工作了:2014-12-05 11:42:03.581 core_sdk_测试[52209:6913207]文件上载失败,错误为:error Domain=dropbox.com Code=1001操作无法完成。dropbox.com错误1001。UserInfo=0x7f91b0c35a10{sourcePath=/bad/path.txt,destinationPath=/Testing/path.txt}2014-12-05 11:42:03.581核心测试[52209:6913207]错误数据:/bad/path.txt