Melody
Melody

Reputation: 1203

File Sharing is not working in Xamarin iOS

I am using the below code to share the file/image to other apps using xamarin ios. But it is not working properly. No exceptions. Code executing properly. But the app list is not launching. What is an issue in below code? Do we need to do any configuration settings changes in the project?

var documentName = shortName + ".pdf";
            var ContentPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var fullFilename = Path.Combine(ContentPath, documentName);

            NSData dataToShare = NSFileManager.DefaultManager.Contents(fullFilename);
            var items = new NSObject[] { dataToShare };

            var controller = new UIActivityViewController(items, null);
            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(controller, true, null);

Upvotes: 3

Views: 456

Answers (1)

Valerio C
Valerio C

Reputation: 37

I'm using this code and it is working properly:

    var url = NSUrl.FromFilename(this.filePath);
    var item = url.Copy();
    var activityItems = new[] { item };
    var activityController = new UIActivityViewController(activityItems, null);

    float width = (float)this.PdfView.Frame.Width;
    float height = (float)this.PdfView.Frame.Height;

    UIPopoverController popoverController = new UIPopoverController(activityController);
    popoverController.SetPopoverContentSize(new CGSize(width, height), true);
    popoverController.PresentFromRect(new CGRect(0, 0, width, height), this.MainView, 0, true);

Upvotes: 1

Related Questions