![](/img/trans.png)
[英]Passed string from the another ViewController is not working with NSUrl
[英]NSURL from string not working
编写了一种方法来提取temp文件夹中的zip文件,并且已使类中的所有方法都使用NSURL而不是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-885CF8757931 / tmp / 715F6E97-968B-4FD9-A517-D9C2320A85A3-3213-0000043B8B4AFD91 / 900156_d378ef9fe1 2
URL = NULL
destPath使用NSTemporaryDirectory
与globallyUniqueString
从NSProcessInfo
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
尝试这个
结果为空,因为您的destPath
变量包含相对的URL路径而不是完整的URL。对于NSURL
,如果需要本地路径,则需要完整的路径,例如http://web.com/you/file/path.html
,然后它应该类似于file:///path/to/your/file.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.