Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After iOS 7 update pathForResource: returns nil

Yesterday I updated to the newest iOS version and discovered that a crucial piece of my code fails to work properly.

// file is @"2/3/3-bottom-cen.png"
NSString *filePath = [[NSBundle mainBundle] pathForResource:file 
                                                         ofType:nil
                                                    inDirectory:@"VillageImages"];

This code results in nil value for filePath and it happens only on iOS7 - the code works correctly on previous versions. I searched and failed to find any recent related problems so I'm asking here for any directions.

like image 594
Alexander Avatar asked Sep 19 '13 07:09

Alexander


Video Answer


1 Answers

Just found out that apparently you can't include path information in the first argument for pathForResource:ofType:inDirectory: anymore, just the file name.

i.e. 'working' syntax for iOS7 would be

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"3-bottom-cen.png" 
                                                         ofType:nil
                                                    inDirectory:@"VillageImages/2/3"];
like image 63
Alexander Avatar answered Oct 07 '22 17:10

Alexander