ios文件保存路径问题

NSArray *path1=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);//数据所在缓存的绝对路径
    NSArray *path2=NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);//数据所存桌面的绝对路径
    NSArray *path3=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSLocalDomainMask, YES);//数据所在缓存的相对路径
    NSArray *path4=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//数据所在文件documents的绝对路径
    NSArray *path5=NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);//数据所在文件Library/Documentation的绝对路径
    NSArray *path6=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);//数据所在文件Library的绝对路径
    NSArray *path7=NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, NSUserDomainMask, YES);//数据所在文件Library的绝对路径
    NSString *destPath = NSHomeDirectory();

打印的结果:

path1=(
    "/Users/yinsuke/Library/Application Support/iPhone Simulator/6.0/Applications/FB3B8EAF-63D9-4CFE-878C-2692093CC763/Library/Caches"
)
path2=(
    "/Users/yinsuke/Library/Application Support/iPhone Simulator/6.0/Applications/FB3B8EAF-63D9-4CFE-878C-2692093CC763/Desktop"
)
path3=(
    "/Library/Caches"
)
path4=(
    "/Users/yinsuke/Library/Application Support/iPhone Simulator/6.0/Applications/FB3B8EAF-63D9-4CFE-878C-2692093CC763/Documents"
)
path5=(
    "/Users/yinsuke/Library/Application Support/iPhone Simulator/6.0/Applications/FB3B8EAF-63D9-4CFE-878C-2692093CC763/Library/Documentation"
)
path6=(
    "/Users/yinsuke/Library/Application Support/iPhone Simulator/6.0/Applications/FB3B8EAF-63D9-4CFE-878C-2692093CC763/Library"
)path7=(
    "/Users/yinsuke/Library/Application Support/iPhone Simulator/6.0/Applications/FB3B8EAF-63D9-4CFE-878C-2692093CC763/Library",
    "/Users/yinsuke/Library/Application Support/iPhone Simulator/6.0/Applications/FB3B8EAF-63D9-4CFE-878C-2692093CC763/Developer"
)

得出的结论:
    NSSearchPathForDirectoriesInDomains(“想要查找的目录”,“想要从哪个路径区域保护区查找”)
查找的区域:
typedef NS_OPTIONS(NSUInteger, NSSearchPathDomainMask) {
    NSUserDomainMask = 1,       // 用户的主目录
    NSLocalDomainMask = 2,      // 当前机器的本地目录
    NSNetworkDomainMask = 4,    // 在网络中公开可用的位置
    NSSystemDomainMask = 8,     // 被苹果系统提供的,不可更改的位置 (/System)
    NSAllDomainsMask = 0x0ffff  // 上述所有及未来的位置
};
想要查找的目录:
NSApplicationDirectory = 1,             // 到applications (Applications)目录下
    NSDemoApplicationDirectory,             // 到Applications/Demos目录下
    NSDeveloperApplicationDirectory,        // 到Developer/Applications目录下.
    NSAdminApplicationDirectory,            // 到Applications/Utilities目录下
    NSLibraryDirectory,                     // 到Library目录下
    NSDeveloperDirectory,                   // 到Developer目录下.
    NSUserDirectory,                        // 到用户的主目录下
    NSDocumentationDirectory,               // 到documentation (Documentation)的目录下
    NSDocumentDirectory,                    // 到documents (Documents)目录下
    NSCoreServiceDirectory,                 // CoreServices目录的位置 (System/Library/CoreServices)
    NSAutosavedInformationDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 11,   // 自动保存的文档位置 (Documents/Autosaved)
    NSDesktopDirectory = 12,                // 本地用户的桌面
    NSCachesDirectory = 13,                 // 本地缓冲区目录(Library/Caches)
    NSApplicationSupportDirectory = 14,     // 本地应用支持文件目录 (plug-ins, etc) (Library/Application Support)
    NSDownloadsDirectory NS_ENUM_AVAILABLE(10_5, 2_0) = 15,              // 本地下载downloads目录
    NSInputMethodsDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 16,           // 输入方法目录 (Library/Input Methods)
    NSMoviesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 17,                 // 电影目录 (~/Movies)
    NSMusicDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 18,                  // 音乐目录 (~/Music)
    NSPicturesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 19,               // 图片目录 (~/Pictures)
    NSPrinterDescriptionDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 20,     // PPDs目录 (Library/Printers/PPDs)
    NSSharedPublicDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 21,           // 本地用户分享目录 (~/Public)
    NSPreferencePanesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 22,        // PreferencePanes目录的位置使用系统的偏好设置 (Library/PreferencePanes)
    NSApplicationScriptsDirectory NS_ENUM_AVAILABLE(10_8, NA) = 23,      // 本地用户 scripts 文件夹,对于所需的应用(~/Library/Application Scripts/code-signing-id)
    NSItemReplacementDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 99,        // For use with NSFileManager's URLForDirectory:inDomain:appropriateForURL:create:error:
    NSAllApplicationsDirectory = 100,       // 应用能够发生的所有路径
    NSAllLibrariesDirectory = 101,          //资源可以发生的所有目录
    NSTrashDirectory NS_ENUM_AVAILABLE(10_8, NA) = 102                   // 垃圾存放目录
};
NSHomeDirectory()只能到达用户的主目录
打印结果: /Users/yinsuke/Library/Application Support/iPhone Simulator/6.0/Applications/FB3B8EAF-63D9-4CFE-878C-2692093CC763
NSString *tempPath = NSTemporaryDirectory();
/Users/yinsuke/Library/Application Support/iPhone Simulator/6.0/Applications/FB3B8EAF-63D9-4CFE-878C-2692093CC763/tmp/  
NSString *fullName=NSFullUserName();
当前用户的一个完整用户名,在需要的路径下可以插入进去。
NSString *userName=NSUserName();
返回当前用户的登陆用户名
NSString * NSHomeDirectoryForUser ( NSString *userName );
返回指定用户名的用户根目录(home)
NSString * NSOpenStepRootDirectory (void);
返回当前用户的系统根目录

转自:http://blog.sina.com.cn/s/blog_923fdd9b01014fun.html

posted @ 2015-08-26 16:03  王 彪  阅读(862)  评论(0编辑  收藏  举报