Search code examples
ioszipnsbundle

NSBundle cannot recognize recent unzip files


I have a zip file to contain all necessary text files in my project. When the app launched for the first time, I unzipped file using ZipArchive. Then when I tried to locate one of my unzipped file to open using:

NSURL *fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[engViDictionaryStore stringByDeletingPathExtension] ofType:[engViDictionaryStore pathExtension]]];

The app crashed with an exception "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'". However, when I launch the app for second time, it could locate unzipped files and works well.

I want to ask if there is anyway for NSBundle recognises my unzipped files right after unzip them.


Solution

  • The bundle cannot be changed or modified once app has been deployed|installed [even during testing].

    You must extract the files into some other directory most probably documents directory & access your files form there.