gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 00:25:37 25 4
gpt4 key购买 nike

我正在使用以下代码获取附件内容并创建一个 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');

关于javascript - 如何在 Cordova iOS 应用程序中打开 blob 内容的附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43110114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com