简体   繁体   English

使用UIActivityViewController共享音频文件

[英]Share Audio file using UIActivityViewController

I am not able to see any item in UIActivityViewController. 我无法在UIActivityViewController中看到任何项目。 I want to share Audio file to Available Sharing options in iPhone device. 我想将音频文件分享到iPhone设备中的可用共享选项。

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html

Review this doc, it will help you. 查看此文档,它会对您有所帮助。

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

Above answer worked for me after little bet struggle.I think there is some issue to access file path .here is modified and tested code. 在小赌注之后,上面的答案对我有用。我认为访问文件路径存在一些问题。这是经过修改和测试的代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM