Search code examples
iosswiftuiactivityviewcontrollerfile-sharing

Sharing a file through my ios Application with UIActivityViewController


I have some files that want to share with any application. I use this code

var fileDAta = NSData.FromFile(path);

UIActivityViewController activityViewController = new UIActivityViewController
                        (new NSObject[]{ fileDAta }, null); //(items, null);

PresentViewController(activityViewController,true,null);

enter image description here

As you see, it should be more application but as a default, there is just the Mail App. it is the same for real device.. (I also installed Gmail and Outlook but there is not on the list or on the more list)

Anyway,when i select the Mail, it cannot be attached ..

enter image description here

What I should change?


Solution

  • Use the following code for sharing but remember respective applications(gmail,twitter etc) for sharing must be installed on your device and configured.

     UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems: fileDAta applicationActivities:nil];
    activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll]; //or whichever you don't need
    [self presentViewController:activityVC animated:YES completion:nil];