Xamarin-ios shares and receives an audio file

How can I share an audio file with my application in other applications and receive audio files from other applications?

I need this functionality: img

I can not connect the audio file. Here is the code snippet:

var fileData = NSUrl.FromFilename(path); var item = UIActivity.FromObject(@"<html><body><b>URL</b>: <a href='" + url + "'>" + url + "</a></body></html>");// NSObject.FromObject(uiImage); var activityItems = new[] { fileData }; NSString message = (NSString)"Test"; var activityController = new UIActivityViewController(activityItems, null); activityController.SetValueForKey(NSObject.FromObject("The subject value"), new NSString("subject")); var topController = UIApplication.SharedApplication.KeyWindow.RootViewController; while (topController.PresentedViewController != null) { topController = topController.PresentedViewController; } topController.PresentViewController(activityController, true, () => { }); 

I would also like to add a subject and body if the file is attached as mail.

tried this but no luck getting an error .:

 activityController.SetValueForKey(NSObject.FromObject("The subject value"), new NSString("subject")); activityController.SetValueForKey(NSObject.FromObject("The body value"), new NSString("body")); 

I would also like to receive audio files shared by other applications. I made this function in android using dependency services and intent filters. For android, the code is added to mainactivity.cs, where I use intent filters to receive audio files from another application. How to do it in iOS?

+7
source share
1 answer

You can share and receive files by sharing data between the main application and the extension. Please note that your application and application extension must belong to the same application group.

+1
source

All Articles