簡體   English   中英

來自字符串的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使用NSTemporaryDirectorygloballyUniqueStringNSProcessInfo

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM