iOS学习(OC语言)知识点整理
每个ios应用都有自己的应用沙盒,应用沙盒就是文件系统目录,与其他应用放入文件 系统隔离,ios系统不允许访问
其他应用的应用沙盒,但在ios8中已经开放访问(extension)
1 NSString *sandBox=NSHomeDirectory();
1 //NSSearchPathForDirectoriesInDomains 返回绝对路径 2 //NSSearchPathForDirectoriesInDomains(要查找的目录, 是否是用户主目录, YES/NO 是否获取全路径); 3 NSArray *arry= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 4 NSLog(@"%@",[arry lastObject]);
1 NSArray *arry2= NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);2 NSLog(@"%@",[arry2 lastObject]);
1 NSArray *arry3= NSSearchPathForDirectoriesInDomains(NSCachesDirectory, 2 NSUserDomainMask, YES);3 NSLog(@"%@",[arry3 lastObject]);
1 NSArray *arry4= NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);2 NSString *path=[arry4 lastObject];3 path=[path stringByAppendingPathComponent:@"Preferences"];4 NSLog(@"%@",path);
1 NSString *tmp=NSTemporaryDirectory();2 NSLog(@"%@",tmp);
1 NSArray *arry4= NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);2 NSString *path=[arry4 lastObject]; 3 path=[path stringByAppendingPathComponent:@"Preferences/Test.txt"];4 NSString *str=@"abcdefg";5 [str writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
1 //保存选择结果到沙盒2 [[NSUserDefaults standardUserDefaults] setObject:_result forKey:@"userPrama"]; //立即同步数据 [[NSUserDefaults standardUserDefaults] synchronize]; 4 //从沙盒取出保存结果5 NSString *result = [[NSUserDefaults standardUserDefaults] valueForKey:@"userPrama"];
新闻热点
疑难解答