SandBox-获取folder路径

作者: alvin_ding | 来源:发表于2015-07-23 12:52 被阅读75次
    -Documents
    -Library
        -Caches
        -References
    -tmp
    

    获取根目录

    真机和模拟器路径可能不同,待验证
    NSString *sandBoxRootDir = NSHomeDirectory();
    

    获取Documents路径

    // NSSearchPathForDirectoriesInDomains返回的是一个数组,但这里第一个参数是NSDocumentDirectory,返回数组里只有一个,所以用了lastObject, 也可以用[paths objectAtIndex:0]
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths lastObject];
    

    获取Library路径

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *libraryDirectory = [paths lastObject];
    

    获取Caches路径

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachesDirectory = [paths lastObject];    
    

    Preferences路径

    通过NSUserDefaults存取数据

    获取tmp路径

    NSString *tmpDirectory = NSTemporaryDirectory();
    

    相关文章

      网友评论

        本文标题:SandBox-获取folder路径

        本文链接:https://www.haomeiwen.com/subject/ivipqttx.html