Search code examples
ioscordovazipdirectoryunzip

Confused about phonegap and IOS, need to get file from 'www' path from 'Plugin' folder


I am using phonegap for IOS. I created a Plugin to unzip files. But now I am trying to test it but its unable to get the correct file path I'm assuming. Right now here is the snippet of where I cal the unzip method, from my ZipArchive plugin class:

NSLog(@"Trying to unzip file");
if([ za UnzipOpenFile:@"../www/data/test.zip"]){
  NSLog(@"UnzipOpenFile passed");
}

The structure of the phonegap is something like this

- ProjectName
  - www
    - data
      - test.zip
  - Plugin
    - ZipArchive.m //where the above snippet lies

I am thinking I can't use relative path like that because in the end product, when compiled and testing on simulator, the path will probably be different. How would I access the www/data folder from ZipArchive.m? Thanks.


Solution

  • You should be able to get a path to things in the www folder with:

    [[[NSBundle mainBundle] resourcePath]
     stringByAppendingPathComponent:@"www/data/test.zip"];
    

    Where are you planing to unzip to? Im quite sure the resource path is read-only when running on a real device. But the documents path and a tmp folder is writeable.

    http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/RuntimeEnvironment/RuntimeEnvironment.html