在NSURL中存储本地路径

时间:2014-10-28 22:09:05

标签: ios objective-c

有关在文档文件夹中获取文件的URL的问题。

我正在尝试将本地网址带到下一个viewcontroller来播放这首歌。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
MSHLocalPlayerVC *playerVC = [segue destinationViewController];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *strURL = [documentsPath stringByAppendingPathComponent: [self.filePathArray objectAtIndex:[self.tableView indexPathForSelectedRow].row]];

playerVC.urlLocalSong = [NSURL URLWithString:strURL];
...
}

结果:

strURL:  /var/mobile/Containers/Data/Application/64000095-51F9-47D1-B152-6D1F8369A01F/Documents/mySong.mp3

playerVC.urlLocalSong:nil

为什么?

1 个答案:

答案 0 :(得分:2)

尝试使用playerVC.urlLocalSong = [NSURL fileURLWithPath:strURL];