Ios 将文件保存在应用程序';主目录
App.App/here.text下的txt文件? 目前我找到了Ios 将文件保存在应用程序';主目录,ios,xcode,Ios,Xcode,App.App/here.text下的txt文件? 目前我找到了NSSearchPathForDirectoriesInDomains NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] error:NULL];
NSSearchPathForDirectoriesInDomains
NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] error:NULL];
但它放在文件下。我可以将其保存在Appname.app/下吗
我可以在哪个级别列出读取的文件?
/专用/var/containers/Bundle/Application/EF4585FC-743D-409D-83A9-B8A298D44C74/App.App
NSString * path = [[NSBundle mainBundle] resourcePath];
[path stringByDeletingLastPathComponent];
NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[path stringByDeletingLastPathComponent] error:NULL];
NSLog(@"sss..%@",path );
NSLog(@"sss..%@",[path stringByDeletingLastPathComponent]);
NSString *stringToWrite = @"1\n2\n3\n4";
NSString *filePath = [path stringByAppendingPathComponent:@"main.jsbundle"];
[stringToWrite writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
[dirs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(@"sss...%@", obj);
}];
查找资源路径:
NSString * path = [[NSBundle mainBundle] resourcePath];
path = [path stringByAddingPathComponent:@"myFileName.myExtension"];
要获取您可以使用的文件,请执行以下操作:
NSString * path = [[NSBundle mainBundle] pathForResource:@"myFileName" ofType:@"myExtension"];
但是请注意,不建议在应用程序包中保存文件,特别是因为代码签名。长话短说:
不,你不能。由于明显的原因,无法写入应用程序包。/Users/xxx/Library/Developer/CoreSimulator/Devices/BB4BCA21-7A1D-4444-8422-CD13185334F1/data/Containers/bundle/application/BD2F18D5-7BB6-425A-B9BC-8E9FC9D5C29F/App.App,这是我想我需要在这里写的资源路径,虽然IOS捆绑包与MacOS上的捆绑包具有相同的结构,但事实并非如此,抱歉。显然,所有内容都在第一级,因此,是的,您可以将其视为资源目录(但二进制文件也在那里:)。我编辑了我的答案。/private/var/containers/Bundle/Application/EF4585FC-743D-409D-83A9-B8A298D44C74/App.App,,,其他一些应用确实写入了App.App。我解压缩并看到了图像和自定义文件否,你不能。写入应用程序包将使代码签名无效。我可以重写与应用程序文件夹相同级别的文件吗?因此,更进一步,文档级别否,您只能将文件写入应用程序容器,甚至只能将文件写入特定文件夹。/private/var/containers/Bundle/application/0D42BEFF-FE20-4A31-A939-EDC3648D69E8/App.App我可以在这里写入什么级别?我无法在应用程序目录中列出文件夹。您不能列出的部分不清楚?将自定义文件写入
文档
或应用程序支持
文件夹。