Sharing an audio file using the UIActivityViewController

I cannot see any item in the UIActivityViewController. I want to share an audio file with the available sharing options on my iPhone.

+5
source share
2 answers

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

Check out this document, 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]; 
+8
source

The above answer worked for me after a bit of a fight for a bet. I think there is some problem with accessing the file path. The code has been modified and verified here.

  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
source

Source: https://habr.com/ru/post/1247863/


All Articles