首先上代码我们往沙盒存一个文件
-(void)WriteToSandbox{
UIView *v = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
v.backgroundColor = [UIColor purpleColor];
[self.view addSubview:v];
//Document目录 documents (Documents)
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *path = [paths objectAtIndex:0];
NSLog(@"%@",path);
// //Libaray目录 various documentation, support, and configuration files, resources (Library)
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES);
// NSString *path = [paths objectAtIndex:0];
//
// //Cache目录 location of discardable cache files (Library/Caches)
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
// NSString *path = [paths objectAtIndex:0];
//通过归档把v 转成NSData