I have stored the recorded audios in the Document folder of the app. When I pass the recorded file to the activity controller, it always returns nil and I am getting the following error:

[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]

My code:

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];

Any help?

有帮助吗?

解决方案

Alright. Managed to resolve by changing from

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

to this

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

Hope this helps other who has similar problem.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top