我必须从iOS 6中的文档库访问图像。
strImgSign = [NSString stringWithFormat:@"%@/Documents//%@", NSHomeDirectory(),strImgSign];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *strImgSign = [[arrNameFinal objectAtIndex:indexPath.row] objectForKey:@"signimage"];
/var/mobile/Applications/D912ACC0-5B23-49B2-B9F1-E45ECD713553/Documents//docSign6167Feb13,2015-12.03.26.png
但iOS 7,8中的图像访问是完美的工作。
答案 0 :(得分:1)
您不应该从NSHoneDirectory
构建目录,也不应使用字符串中的路径分隔符。
构建目录的正确方法:
NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
imagePath = [imagePath stringByAppendingPathComponent:strImgSign];
但更好和唯一正确的方法是使用正确的目录:
NSString *documentPath =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *imagePath = [documentPath stringByAppendingPathComponent:strImgSign];
答案 1 :(得分:0)
您的路径中还有一个/
:
strImgSign = [NSString stringWithFormat:@"%@/Documents//%@", NSHomeDirectory(),strImgSign];
将其更改为:
strImgSign = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),strImgSign];
但正如@rckoenes所提到的,这不是构建文件系统路径的正确方法。如果您的图像位于文档目录中,则可以使用:
NSString *docDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *yourImagePath = [docDirectory stringByAppendingPathComponent:strImgSign];
但我不确定它在iOS 7和iOS 8中是如何起作用的
答案 2 :(得分:-1)
NSString * filename = [filepart lastObject];
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString documentsDirectory = [paths objectAtIndex:0];
NSString inboxPath = [documentsDirectory stringByAppendingPathComponent:@" Inbox"];
NSString * filePath = [inboxPath stringByAppendingPathComponent:filename];