After updating iOS 7 pathForResource: returns nil

Yesterday I upgraded to the newest version of iOS and found that the critical part of my code is not working properly.

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

This code results in a nil value for filePath, and this only happens on iOS7 - the code works correctly in previous versions. I searched and could not find any recent related issues, so I ask here about any directions.

+6
source share
1 answer

It just turned out that, apparently, you can no longer include path information in the first argument to pathForResource:ofType:inDirectory: just the file name.

i.e. The "working" syntax for iOS7 would be

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

Source: https://habr.com/ru/post/954138/


All Articles