首页 文章

xamarin ios用filepath打开acrobat阅读器

提问于
浏览
0

此代码打开acrobat阅读器

var url = new NSUrl($"com.adobe.adobe-reader://");
UIApplication.SharedApplication.OpenUrl(url);

我试图给这个文件路径,但我收到错误

var url = new NSUrl($"com.adobe.adobe-reader://{filepath}");

var url = new NSUrl($"com.adobe.adobe-reader:{filepath}");

1 回答

  • 1

    我不确定您是否可以使用此方法直接在另一个应用程序中打开文件 . 相反,我认为你需要使用 UIDocumentInteractionController 打开一个弹出窗口,允许用户选择应用程序来打开PDF . 所以试试这个:

    NSUrl adobeUrl = new NSUrl($"com.adobe.adobe-reader:");
    NSUrl fileUrl = NSUrl.FromFilename(filePath);
    UIDocumentInteractionController docController = UIDocumentInteractionController.FromUrl(fileUrl);
    if (UIApplication.SharedApplication.CanOpenUrl(adobeUrl))
    {
        docController.PresentOpenInMenu(this.View.Frame, this.View, true);
    }
    else
    {
        // throw error
    }
    

    您还需要将Adobe Reader URL Scheme添加到Info.plist中 . 在文本编辑器中打开Info.plist并输入以下内容:

    <key>LSApplicationQueriesSchemes</key>
        <array>
            <string>com.adobe.adobe-reader</string>
        </array>
    

    就在最后一个标签之前,例如

    <plist version="1.0">
    <dict>
        ...
        <key>LSApplicationQueriesSchemes</key>
        <array>
            <string>com.adobe.adobe-reader</string>
        </array>
    </dict>
    </plist>
    

    没有它,你将失败 CanOpenUrl 测试,所以这就是为什么没有发生...虽然如果你查看了应用程序输出,iOS确实发送了一个你需要这样做的消息,例如:

    -canOpenURL: failed for URL: "com.adobe.adobe-reader:" - error: "This app is not allowed to query for scheme com.adobe.adobe-reader"
    

    我相信,对于像 var url = new NSUrl($"com.adobe.adobe-reader://{filepath}"); 这样的东西,文件实际上需要已经在Adobe Acrobat的文件容器中 . 有关详细信息,请参阅此SO帖子:https://stackoverflow.com/a/21913788/2913599 [注意:我无法使用此方法,即使已经在Adobe Acrobat的文件中使用了pdf]

相关问题