【发布时间】:2014-12-11 11:15:44
【问题描述】:
我正在尝试将图像保存到我的本地资源路径中。我已经编写了以下代码来将图像保存在本地。
NSString *resoursePath=[[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Library/Caches"]];
NSString *filePath=[NSString stringWithFormat:@"%@/%@", resoursePath, fileName];
BOOL isDirectory=NO;
if(![[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory])
{
NSError *error;
if([self writeToFile:filePath options:NSDataWritingAtomic error:&error])
NSLog(@"Successfully saved");
else
NSLog(@"%@", error);
}
在 iOS 7 上运行良好。但在 iOS 8 中出现问题。它在控制台中写入以下错误。
Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x7f7f8adb0cf0 {NSFilePath=/Users/tapas/Library/Developer/CoreSimulator/Devices/1F61698C-FAF4-4F27-9DA1-14B3F7227308/data/Containers/Bundle/Application/A38802B2-CC82-4220-BA2D-A0FD225016D7/Library/Caches/635471351432677268_iPhoneThumb.jpg, NSUserStringVariant=Folder, NSUnderlyingError=0x7f7f8ae0c100 "The operation couldn’t be completed. No such file or directory"
请建议我该怎么做。提前致谢。
【问题讨论】:
-
投反对票的你能回答我的问题吗??
标签: objective-c iphone ipad ios7 ios8