开发者社区> 问答> 正文

关于程序创建目录,没有禁止用户查看 的问题

applicationSupportDirectory中创建directory 。我认为applicationSupportDirectory 不允许用户看内部数据。因为这样我才选它,但是好像不是这样。

请高手告诉我怎么回事?谢谢

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,   NSUserDomainMask, YES);
NSString *applicationDirectory = [paths objectAtIndex:0]; // Get directory
NSString *dataPath = [applicationDirectory stringByAppendingPathComponent:@"drawings"];

if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]){

NSError* error;
if([[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error])
  ;// success
else
{
  NSLog(@"Failed");
}
}
}

展开
收起
爵霸 2016-03-23 09:51:56 1792 0
1 条回答
写回答
取消 提交回答
  • 打印你得dataPath 你会发现 .../Applications/2D....566A/Library/Application Support/drawings
    Application Support目录是不存在的,
    所以当你createDirectoryAtPath:filePathAndDirectory withIntermediateDirectories:NO 会返回NO
    因为withIntermediateDirectories: 意思是是否创建最终目录的不存在的父目录,
    所以改成createDirectoryAtPath:filePathAndDirectory withIntermediateDirectories:YES就可以创建成功了
    官方解释:
    `
    createIntermediates
    If YES, this method creates any non-existent parent directories as part of creating the directory in url. If NO, this method fails if any of the intermediate parent directories does not exist. This method also fails if any of the intermediate path elements corresponds to a file and not a directory.
    `

    2019-07-17 19:10:20
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多