标签:
在模拟器中运行iOS程序,都会为该程序创建一个沙盒(SandBox)。想要找到沙盒目录,先运行Finder,然后在Finder的菜单栏找到前往—前往文件夹…,在打开的窗口输入
ios7之前
/Users/dante/Library/Application Support/iPhone Simulator/6.1/Applications/4FD4E9ED-EFAF-495A-8BA8-653DC43E8C8E/Documents/play.mp4
ios7之后
/Users/mac/Library/Developer/CoreSimulator/Devices/A747DC96-ED64-4E1F-AB15-8EC65E015F9D/data/Containers/Data/Application/B4864589-CBAA-4964-B993-146A99764188/Documents/play.mp4
其中,mac是指用户在Mac系统中的用户名。
//获得路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *fullpath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"play.mp4"];
NSLog(@"%@",fullpath);
//取出路径的内容
NSData *cityData = [NSData dataWithContentsOfFile:fullpath];
//如果本地已有数据就不再请求
if (cityData)
{
self.playerController=[[MPMoviePlayerViewController alloc] init];
[self presentMoviePlayerViewControllerAnimated:self.playerController];
[self.playerController.moviePlayer play];
}
else
{
//下载到本地
NSURL *url = [NSURL URLWithString:@"http://vdata.tool.hexun.com/2013-07-15/156151759_m.mp4"];
//把数据写入属性列表
//获得路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *fullpath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"play.mp4"];
NSData *data=[[NSData alloc]initWithContentsOfURL:url];
[data writeToFile:fullpath atomically:YES];
}
标签:
原文地址:http://www.cnblogs.com/huangzs/p/4463498.html