当我在iOS8 beta3和beta5上测试我的应用程序时,我发现一个关于[UIImage imageWithContentsOfFile:]的bug。
当图像资源存储在主包的子包中时,如果我们通过以下方法初始化UIImage,则会返回nil:
NSString *testBundlePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"bundle”];
NSBundle *bundle = [NSBundle bundleWithPath:testBundlePath];
NSString *path = [bundle pathForResource:@"play.png" ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path]; //iOS8 image = nil, iOS7 image != nil
但是当图像资源存储在主捆绑包中时,可以通过以下方法成功初始化UIImage:
NSString *path = [[NSBundle mainBundle] pathForResource:@"play.png" ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path]; //iOS8 and iOS7 image != nil
我们在iOS8 beta3下发现了这个问题,并且在iOS8 beta 5下仍然存在。
The Demo app directory structure was below:
XXX.app
|----test~ipad.bundle
|----play.png
|----test~iphone.bundle
|----play.png
|----play.png
|----play~iphone.png
|----play~ipad.png
......
有人与我遇到了同样的问题吗?我认为这是iOS8上的一个bug,因此,许多应用程序都使用bundle来组织资源,例如图像。但现在,这个bug会使成千上万的应用程序变得丑陋和难以使用。我们真的希望苹果公司能在下一个版本中修复这个bug,否则,我的所有应用程序都必须为这个bug开发一个新版本!