开发者

i can unzip the folder but how to access that folder form iphone

开发者 https://www.devze.com 2023-01-11 09:46 出处:网络
this code allows you to unzip file and create a folder in documents lets say List and this List folder is having all the unzip data now how to access that List content??

this code allows you to unzip file and create a folder in documents lets say List and this List folder is having all the unzip data now how to access that List content??

     NSArray *paths = 
     NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

     NSString *documentsDirectory = [paths objectAtIndex:0];

     NSString *saveLocation = 
     [documentsDirectory stringByAppendingString:@"myfile.zip"];

     NSFileManager* fileManager = [NSFileManager defaultManager];

     if ([fileManager fileExistsAtPath:saveLocation]) {
         [fileManager removeItemAtPath:saveLocation error:nil];
         NSLog(@" file path %@",fileManager);
     }

     NSURLRequest *theRequest = 
     [NSURLRequest requestWithURL:
      [NSURL URLWithString:@"http://localhost/list.zip"]
                      cachePolicy:NSURLRequestUseProtocolCachePolicy
                  timeoutInterval:60.0];    

     NSData *received = 
     [NSURLConnection sendSynchronousRequest:theRequest
                           returningResponse:nil error:nil];    

     if ([received writeToFile:saveLocation atomically:TRUE]) {      
         NSString *cmd = 
         [NSString stringWithFormat:@"unzip \"%@\" -d\"%@\"", 
          saveLocation, documentsDirectory];       

         // Here comes the magic...
         system([cmd UTF8String]);       
     }


     NSLog(@"loca is %@", saveLocation);


      NSLog(@"%@", [[NSFileManager defaultManager] contentsOfDirectoryAtPath开发者_StackOverflow中文版:documentsDirectory error:nil]);  // i can see list folder but how to get the content outside??


to unzip file on iphone read this - http://www.touch-code-magazine.com/update-dynamically-your-iphone-app-with-new-content/


You can access it with NSFileManager's

- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error.

0

精彩评论

暂无评论...
验证码 换一张
取 消