【问题标题】:File Sharing is not working in Xamarin iOS文件共享在 Xamarin iOS 中不起作用
【发布时间】:2017-07-04 11:46:39
【问题描述】:

我正在使用以下代码将文件/图像共享给使用 xamarin ios 的其他应用程序。但它不能正常工作。没有例外。代码正确执行。但应用列表未启动。下面的代码有什么问题?我们需要在项目中做任何配置设置更改吗?

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);

【问题讨论】:

  • 任何想法,如何让它工作?

标签: xamarin.ios sharing file-sharing


【解决方案1】:

我正在使用这段代码,它工作正常:

    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);

【讨论】:

    猜你喜欢
    • 2014-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多