Use UIActivityViewController to share all types of files

前端 未结 1 929
小鲜肉
小鲜肉 2021-01-07 13:46

I want to use UIActivityViewController to share files from my iOS app. The main question for me is how do I handle different file types.

What I\'v got s

相关标签:
1条回答
  • 2021-01-07 14:26

    I tried to implement UIActivityItemProvider, but here again not all apps where shown for the corresponding filetype. E.g. for a docx-document Word was not shown.

    Now I switched to UIDocumentInteractionController and now there are many apps available.

    UIDocumentInteractionController documentController = new UIDocumentInteractionController();
    documentController.Url = new NSUrl(filepath, false);
    string fileExtension = Path.GetExtension(filepath).Substring(1);
    string uti = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension.ToString(), fileExtension, null);
    documentController.Uti = uti;
    
    UIView presentingView = UIApplication.SharedApplication.KeyWindow.RootViewController.View;
    documentController.PresentOpenInMenu(CGRect.Empty, presentingView, true);
    

    Imho there are too many apps, because the file type xml should not be really be supported by a PDF reader, but it is. Nevertheless, it seems to work now thanks to this post:

    In general if you’re sharing an image or url, you might want to use a UIActivityViewController. If you’re sharing a document, you might want to use a UIDocumentInteractionController.

    0 讨论(0)
提交回复
热议问题