获取沙盒文件夹地址


//宏定义
#define JYuserDefaults  [NSUserDefaults standardUserDefaults]
static NSString *accountKey = @"account";
static NSString *pwdKey = @"pwd";
static NSString *rmbKey = @"rmb";
static NSString *autoLoginKey = @"autoLogin";

//        快速做键值对存储
            [JYuserDefaults setObject:_accountField.text forKey:accountKey];
            [JYuserDefaults setObject:_pwdField.text forKey:pwdKey];
            [JYuserDefaults setBool:_rmbPwdSwitch.on forKey:rmbKey];
              [JYuserDefaults setBool:_autoLoginSwitch.on forKey:autoLoginKey];
            [JYuserDefaults synchronize];


//    读取NSUserDefaults存储的数据
       NSString  *account= [JYuserDefaults objectForKey:accountKey];
       NSString  *pwd= [JYuserDefaults objectForKey:pwdKey];
       BOOL  rmb= [JYuserDefaults boolForKey:rmbKey];
       BOOL  autoLogin= [JYuserDefaults boolForKey:autoLoginKey];
    


//           NSString *homePathStr = NSHomeDirectory();
//            NSString*temPathStr = NSTemporaryDirectory();
//            采用拼接的方法能获取想要的文件

            NSString *documentPathStr = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Preferences"];
            
            NSLog(@"%@",documentPathStr);






//获取沙盒根目录 直接调用NSHomeDirectory():
NSString*directory=NSHomeDirectory();
NSLog(@"directory:%@",directory);


//获取Documents路径
NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString*path=[pathsobjectAtIndex:0];
NSLog(@"path:%@",path);

获取Documents文件夹目录,第一个参数是说明获取Doucments文件夹目录,第二个参数说明是在当前应用沙盒中获取。  



//获取Library路径
NSArray*paths=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES);
NSString*path=[pathsobjectAtIndex:0];
NSLog(@"path:%@",path);


//获取Caches路径
NSArray*paths=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
NSString*path=[pathsobjectAtIndex:0];
NSLog(@"path:%@",path);

获取tmp路径

NSString*tmp=NSTemporaryDirectory();
NSLog(@"tmp:%@",tmp);

你可能感兴趣的:(获取沙盒文件夹地址)