将音频文件从文档文件夹传递到活动控制器

时间:2014-02-23 15:16:26

标签: ios audio share nsdata

我已将录制的音频存储在应用的“文档”文件夹中。当我将录制的文件传递给活动控制器时,它总是返回nil,我收到以下错误:

  

[__ NSPlaceholderArray initWithObjects:count:]:尝试从对象插入nil对象[0]

我的代码:

NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

NSString *path = [DOCUMENTS_FOLDER stringByAppendingPathComponent:[fileList objectAtIndex:[indexPath row]]];

NSURL *audioURL = [NSURL URLWithString:path];
NSData *audioData = [NSData dataWithContentsOfURL:audioURL];

self.activityViewController = [[UIActivityViewController alloc]

                               initWithActivityItems:@[audioData] applicationActivities:nil];

[self.activityViewController setValue:@"Recording" forKey:@"subject"];


[self presentViewController:self.activityViewController animated:YES completion:nil];

任何帮助?

1 个答案:

答案 0 :(得分:3)

好的。通过更改

来管理解决
NSURL *audioURL = [NSURL URLWithString:path];
NSData *audioData = [NSData dataWithContentsOfURL:audioURL];
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[audioData] applicationActivities:nil];

到这个

NSURL *audioURL = [NSURL fileURLWithPath:path];
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[audioURL] applicationActivities:nil];

希望这可以帮助其他有类似问题的人。