Ios 来自字符串的NSURL不工作

Ios 来自字符串的NSURL不工作,ios,objective-c,nsurl,Ios,Objective C,Nsurl,编写了一个方法来提取临时文件夹中的zip文件,并使类中的所有方法都是使用NSURL而不是path启动的,但是当尝试将path更改为NSURL时,它返回null //handles all ZIP Extraction -(NSURL*)handleZIPExtractionAtDestination:(NSURL*)destinationURL { NSString *destPath=[[destinationURL path] stringB

编写了一个方法来提取临时文件夹中的zip文件,并使类中的所有方法都是使用NSURL而不是path启动的,但是当尝试将path更改为NSURL时,它返回null

//handles all ZIP Extraction
-(NSURL*)handleZIPExtractionAtDestination:(NSURL*)destinationURL
{
    NSString *destPath=[[destinationURL path]
                     stringByAppendingPathComponent:
                        [[[_archiveURL lastPathComponent] componentsSeparatedByString:@"."]
                         firstObject]];
    
    BOOL result=[SSZipArchive unzipFileAtPath:[_archiveURL path] toDestination:destPath];
    
    if(!result)
    {
        NSLog(@"Couldn't extract the Files.");
        return nil;
    }
    NSLog(@"%@",destPath);
    NSURL *url=[NSURL URLWithString:destPath];
    NSLog(@"%@",url);
  
    return url;
}
结果:

destPath=/private/var/mobile/Containers/Data/Application/43DB7D13-9999-4231-B8AB-885CF875931/tmp/715F6E97-968B-4FD9-A517-D9C2320A85A3-3213-00000 43B8B4AFD91/900156_d378ef9fe1 2

url=null


destPath将
NSTemporaryDirectory
NSProcessInfo
中的
globallyUniqueString
一起使用,结果为空,因为您的
destPath
变量包含相对url路径不完整的url。对于
NSURL
您需要类似
http://web.com/you/file/path.html
如果您想要本地路径,那么它应该类似于
file:///path/to/your/file.html

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];

尝试此方法

只需在destPath变量之前附加
文件://
,那么它应该可以工作使用最小数量的代码行是没有代价的。使用一些中间变量,这样您就有机会检查代码哪里出错了。您的代码处理文件扩展名时出错。请查看文档中有哪些处理文件路径的方法,并使用它们。例如initFileURLWithPath,而不是URLWithString.Thank man。你所说的代码处理文件扩展名错误是什么意思?