pland
pland

Reputation: 858

iOS mainBundle not loading resources

I had a working iOS project, and whilst working on a git branch, the project would suddenly not load any resources from the main Bundle...I'm loading an audio file for a simple AVAudioPlayer with:

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/nadamintrov1.aif", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
NSLog(@"%@", url);
splashScreenAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

and in other ViewControllers I'm also loading other files such as:

    patch = [PdBase openFile:@"klangfarbe6ep.pd" path:[[NSBundle mainBundle] resourcePath]];
if (!patch) {
    NSLog(@"Failed to open patch!");
    // Gracefully handle failure...
}

but whilst both those worked just fine before, now I get "couldn't initialise splash audio player" and for the patch:

open: /var/mobile/Applications/464B65AD-9E2C-42C9-8BBA-12AFD0D48393/Nadam.app/klangfarbe6ep.pd: No such file or directory

klangfarbe6ep.pd: No such file or directory 2012-02-26 12:07:17.332 Nadam[520:707] Failed to open patch!

which is weird...I mean the NSLog(@"%@", url); I put up for the AudioPlayer clearly returns:

2012-02-26 12:06:49.127 Nadam[520:707] file://localhost/var/mobile/Applications/464B65AD-9E2C-42C9-8BBA-12AFD0D48393/Nadam.app/nadamintrov1.aif

so why on earth isn't it loading it? Diff from git over the last few changes don't show anything in the project file that I can see as corruption...

anyone had that happen to them before? any way of debugging it? I read this thread:

What is the alternative of [NSBundle mainBundle] URLForResource:withExtension: in iOS 3 SDK

But can't understand why it was working before and not now with no project changes...

Upvotes: 3

Views: 3001

Answers (1)

Iducool
Iducool

Reputation: 3661

I don't know exactly what is the issue here. But it is the most common problem. In two situations such issue occurs. 1. file path is wrong. 2.File is not included in bundle.
After checking above file path shown by you I don't think it is the issue of file path. But you can check your file is included in target or not. Just right click on your file and select get info. Where check in target your current target is selected or not.

Upvotes: 7

Related Questions