当我在iOS8 beta3和beta5上测试我的应用程序时,我发现了一个关于[UIImage imageWithContentsOfFile:]的错误.
当图像资源存储在主束的子束中时,如果我们通过以下方法初始化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
Run Code Online (Sandbox Code Playgroud)
但是当图像资源存储在主束中时,UIImage Initialization可以通过以下方法成功:
NSString *path = [[NSBundle mainBundle] pathForResource:@"play.png" ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path]; //iOS8 and iOS7 image != nil
Run Code Online (Sandbox Code Playgroud)
我们在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
......
Run Code Online (Sandbox Code Playgroud)
有没有人有同样的问题?我认为这是iOS8上的一个错误,因此,许多应用程序使用bundle来组织资源,例如图像.但是现在,这个bug将使成千上万的应用程序变得丑陋且难以使用.我们真的希望Apple可以在下一个版本中修复这个bug,否则,我的所有app都必须为这个bug开发一个新版本!