如何在 Cordova iOS 应用程序中打开 blob 内容的附件

How to Open Attachments of blob content in Cordova iOS app

我正在使用以下代码获取附件内容并创建一个 blob 来打开附件。内容已成功获取并创建了 blob,但附件未打开,尽管它在 chrome 中作为 Web 应用程序工作,但在 Cordova iOs APP 中不工作。

还有什么要补充的吗

{
var details =
    "Username=username&Password=Password";
var http = new XMLHttpRequest();
http.open("POST", url, true,
    "username",
    "password");
http.setRequestHeader(
    "Content-type",
    "application/x-www-form-urlencoded"
);
http.onreadystatechange = function() { //Call a function when the state changes.
    if (http.readyState == 4 &&
        http.status == 200) {
        var ticket = JSON.parse(
            http.responseText
        ).ticket;
        var xhr = new XMLHttpRequest();
        xhr.open('GET',
            "http://hostname/url",
            true);
        xhr.setRequestHeader(
            "header",
            ticket);
        xhr.responseType =
            'arraybuffer';
        xhr.onload = function() {
            if (this.status ===
                200) {
                var blob =
                    new Blob(
                        [
                            xhr
                            .response
                        ], {
                            type: "application/pdf"
                        });
                var
                    objectUrl =
                    URL.createObjectURL(
                        blob
                    );
                window.open(
                    objectUrl
                ); // blob:file:///835fce36-9a25-4dbb-9e16-d3fcb9d27fef"
            }
        };
        xhr.send();
    }
}
http.send(details);

}

Error : [Error] url ->file:///1811f4d5-17f0-4124-a761-70a4b4d9f361
(anonymous function) (console-via-logger.js:173)
(anonymous function) (logger.js:754)
(anonymous function) (attachmentviewer.js:80)
(anonymous function) (i18n.js:55)
callbackFromNative (cordova.js:293)
nc2 (cordova.js:1022)
[Error] current window.location -
>file:///Users/myname/Library/Developer/CoreSimulator/Devices/D2891D9A-
E669-4F16-849E-
D63532979F00/data/Containers/Bundle/Application/0A917ACE-
9F1B-42B8-B745-C351BAA3A369/Equip%20R2.0.app/www/index.html#/Attachment/30
(anonymous function) (console-via-logger.js:173)
(anonymous function) (logger.js:754)
(anonymous function) (attachmentviewer.js:81)
(anonymous function) (i18n.js:55)
callbackFromNative (cordova.js:293)
nc2 (cordova.js:1022)

使用 InApp 浏览器有效。 InApp 浏览器:Link

cordova.InAppBrowser.open(objectUrl, '_blank', 'location=yes');