menu

开发进行时...

crazy coder

Avatar

iOS 获取用户主目录

使用底层的C函数NSHomeDirectory() 能够访回当前app当前用户的主目录
用户数据都建议放在/Documents中
每一个iOS应用沙盒都有/Documents目录

NSString  *path = [NSHomeDirectory() stringByAppendingString:USER_FILE];


补方法二

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

[paths objectAtIndex:0] 即为/Documents根目录

NSString  *plistPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"myfile.txt"];

想必 XCode 什么的有专门的快捷键帮助打出“NS”吧?