2

Wrote a method to extract zip files in a temp folder and have made such that all the method in class are initiated with NSURL than path but when tried to change path to NSURL it returns 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; } 

Result:

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 uses NSTemporaryDirectory with globallyUniqueString from NSProcessInfo

3
  • There's no price for using the smallest number of lines of code. Use some intermediate variables so you have a chance of checking where your code goes wrong. And your code handles file extensions wrong. Commented Mar 18, 2016 at 8:57
  • Look through the documentation which methods for handling file paths there are, and use them. For example initFileURLWithPath, not URLWithString. Commented Mar 18, 2016 at 8:59
  • thanks man. what do you mean by code handles file extensions wrong? Commented Mar 18, 2016 at 9:41

2 Answers 2

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

try this

Sign up to request clarification or add additional context in comments.

Comments

1

Result is null because your destPath variable holds relative url path not complete url.for NSURL you need complete path like http://web.com/you/file/path.html if you want local path then it should be something like file:///path/to/your/file.html

1 Comment

just append file:/// before your destPath variable then it should work

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.