ios - 来自字符串的 NSURL 不起作用
<p><p>编写了一个在临时文件夹中提取 zip 文件的方法,并使得类中的所有方法都使用 NSURL 而不是路径启动,但是当尝试将路径更改为 NSURL 时,它返回 null。</p>
<pre><code>//handles all ZIP Extraction
-(NSURL*)handleZIPExtractionAtDestination:(NSURL*)destinationURL
{
NSString *destPath=[
stringByAppendingPathComponent:
[[ componentsSeparatedByString:@"."]
firstObject]];
BOOL result= toDestination:destPath];
if(!result)
{
NSLog(@"Couldn't extract the Files.");
return nil;
}
NSLog(@"%@",destPath);
NSURL *url=;
NSLog(@"%@",url);
return url;
}
</code></pre>
<p>结果:</p>
<blockquote>
<p>destPath=/private/var/mobile/Containers/Data/Application/43DB7D13-9999-4231-B8AB-885CF8757931/tmp/715F6E97-968B-4FD9-A517-D9C2320A85A3-3213-0000043B8B4AFD91/900156_d378ef9fe1 2</p>
<p>url=null</p>
</blockquote>
<p>destPath 使用 <code>NSTemporaryDirectory</code> 和 <code>NSProcessInfo</code></p> 中的 <code>globallyUniqueString</code></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>NSURL *fileURL = [ initFileURLWithPath:filePath];
</code></pre>
<p>试试这个</p></p>
<p style="font-size: 20px;">关于ios - 来自字符串的 NSURL 不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/36078624/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/36078624/
</a>
</p>
页:
[1]