0
在iOS 8此代码失败,失败了,但它会在iOS 7写入/读取与交错的双点路径上的iOS 8
UIImage *imageTest = ...
NSString *file = @"../Documents/Test.png";
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent: file];
[UIImagePNGRepresentation(imageTest) writeToFile: fullpath atomically: YES];
UIImage *image = [UIImage imageNamed: file];
工作在iOS 8我需要用这个代替
NSString *file = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Test.png"];
[UIImagePNGRepresentation(imageTest) writeToFile:file atomically:YES];
UIImage *image = [[UIImage alloc] initWithContentsOfFile: file];
...但后来我不得不重构我的项目和第三方库,它使用相对于主包的路径。
在我看来,像"/PathToMainBundle/MyApp.app/../Documents/something"
路径是得不到妥善解决,否则不准在所有的iOS 8
这条道路应该是一样的"/PathToMainBundle/Documents/something"
这为我工作最多iOS8上:'的NSString *文件= [[一个NSBundle mainBundle] pathForResource:@ “SomeFile” ofType:@ “PDF”];'现在我甚至无法看到文件应用程序包。 – Jorgen 2014-09-23 08:38:39
@Jorgen但我需要首先使用相对于主包的路径创建文件,因为我正在使用的库如 – rraallvv 2014-09-23 08:41:48
正如我所说的。使用iOS8时,我无法在使用iExplorer或Xcode 6中的设备窗口查看设备时看到该文件。完全困惑。 – Jorgen 2014-09-23 08:47:24