我无法在UIActivityViewController中看到任何项目。我想将音频文件分享到iPhone设备中的可用共享选项。
答案 0 :(得分:8)
查看此文档,它会对您有所帮助。
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSString *filePath = [docPath stringByAppendingPathComponent:@"sound.aac"];//Audio file
NSURL *fileUrl = [NSURL fileURLWithPath:filePath isDirectory:NO];
NSArray *activityItems = @[fileUrl];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
答案 1 :(得分:0)
在小小的赌注争夺战之后,上面的答案对我有用。我认为访问文件路径存在一些问题。这里是经过修改和测试的代码。
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"sampleFile" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSArray *activityItems = @[soundFileURL];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];