簡體   English   中英

Phonegap 應用程序可用於預覽但不適用於 Android 設備 - Promise

[英]Phonegap app working on preview but not on Android device - Promise

我有一個 Phonegap 應用程序,它可以在預覽應用程序上完美運行,但是當我使用 Phonegap Build 創建一個 APK 並將其安裝在 Android 設備上時,它部分工作,除了 Promise 內的任何代碼。 我添加了一些警報,我注意到它在 Promise 之前停止工作。

我有以下代碼:

    {
        alert('passwordreset before promise');
        return new Promise((resolve, reject) => {
            alert('inside promise');
            this.api.call( '/' + this.endpoint + '/recover', {email: email})
            .then(response => 
            { alert('promise succes');
                resolve(response);
            })
            .catch(errors => 
            {
                reject(errors);
            });

        });
    } 

第一個警報(promise 之前的密碼)被執行,但不執行其他警報。

你知道會發生什么嗎?

你使用安卓工作室嗎? 如果是這樣,請檢查您在 LogCat 選項卡中有什么日志。 您是否設置了正確的 CORS 設置? 看起來您正在發出一些 api 請求。 在 MSDN 中有一篇很好的文章描述了您可能缺少哪些設置: https : //docs.microsoft.com/en-us/visualstudio/cross-platform/tools-for-cordova/security/whitelists?view=toolsforcordova-2017

由於默認情況下禁用 Android 9 明文。 如果問題仍然存在,請驗證您的 network_security_settings.xml(如果已設置)。

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="true">
  <domain includeSubdomains="true">10.0.1.1</domain> <!-- Set local api -->
</network-security-config>

您可以在 Android Manifest 中設置網絡設置文件

<?xml version="1.0" encoding="utf-8"?>
 <manifest>
 <application android:networkSecurityConfig="@xml/network_security_config">
    ...
 </application>
 </manifest>

webview 不支持承諾。 您需要為 ES5 轉譯/編譯您的 JS 代碼。

Promise 是 ES2015 JavaScript 規范(也稱為 ES6)的一部分。

如果您需要 polyfill,請查看https://www.promisejs.org/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM