Share Audio file using UIActivityViewController

后端 未结 2 1310
时光取名叫无心
时光取名叫无心 2021-01-13 06:54

I am not able to see any item in UIActivityViewController. I want to share Audio file to Available Sharing options in iPhone device.

相关标签:
2条回答
  • 2021-01-13 07:26

    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];
    
    0 讨论(0)
  • 2021-01-13 07:49

    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];
    
    0 讨论(0)
提交回复
热议问题