程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-程序創建目錄,沒有禁止用戶查看

ios-程序創建目錄,沒有禁止用戶查看

編輯:編程綜合問答
程序創建目錄,沒有禁止用戶查看

在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");
}
}
}

最佳回答:


打印你得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.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved