Search code examples
javascriptiphoneiosnsbundlensdocumentdirectory

iPhone / iOS - [NSBundle mainBundle] pathForResources not able to see Javascript files


I have added a javascript file to my app resource bundle which I need to move to the documents directory but when I initiate its path for copying it returns null.

Code:

NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"jsFile" ofType:@"js"];
NSString *copyPath = [path stringByAppendingString:@"/jsFile.js"];  //path is the documents dir
NSLog(@"%@", jsPath); //Output of this is (null)

if ([[NSFileManager defaultManager] fileExistsAtPath:jsPath]) //returns false
[[NSFileManager defaultManager] copyItemAtPath:jsPath toPath:copyPath error:nil];

Has anyone very encountered this before?


Solution

  • Check to see if your js-file is compiled, rather than being copied to the bundle. You'll need to look under "build phases" for your current target...