菜鸟教程小白 发表于 2022-12-12 10:49:08

ios - 来自字符串的 NSURL 不起作用


                                            <p><p>编写了一个在临时文件夹中提取 zip 文件的方法,并使得类中的所有方法都使用 NSURL 而不是路径启动,但是当尝试将路径更改为 NSURL 时,它返回 null。</p>
<pre><code>//handles all ZIP Extraction
-(NSURL*)handleZIPExtractionAtDestination:(NSURL*)destinationURL
{
    NSString *destPath=[
                     stringByAppendingPathComponent:
                        [[ componentsSeparatedByString:@&#34;.&#34;]
                         firstObject]];
   
    BOOL result= toDestination:destPath];
   
    if(!result)
    {
      NSLog(@&#34;Couldn&#39;t extract the Files.&#34;);
      return nil;
    }
    NSLog(@&#34;%@&#34;,destPath);
    NSURL *url=;
    NSLog(@&#34;%@&#34;,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]
查看完整版本: ios - 来自字符串的 NSURL 不起作用