Ionic 3:Promise不适用于某些Android设备

时间:2018-03-27 18:51:36

标签: typescript ionic-framework promise ionic3 es6-promise

我在离子功能 loadScript 中使用Promise,当我在浏览器上测试时没关系,当我在某些设备上测试android 4.xx时没关系,但是当我在联想上测试时K5 Note(Android 5.1), Promise不起作用,而且我的android 5.1解雇的调试警报正是:

alert('0');
alert('1');
alert('inside promise');
alert('return promise');

因此它忽略了承诺核心指令,包括:

alert('script loaded');

您将在下面找到源代码+离子信息

Home.ts:

//imports + Decorators
export class HomePage {
  @ViewChild('map') mapElement: ElementRef;
  map: any;

  constructor(public navCtrl: NavController,
              private platform:Platform,
              private geolocation:Geolocation) {
  }

  ionViewDidLoad(){
    alert('0');
    this.loadScript()
    .then( () => {
      alert('initMap1');
      this.initMap();
      alert('initMap2');
    })

    .then( () => {
      console.log('geolocation');
      alert('geolocation')
      setTimeout(() => {
        this.getGeolocation();
      },5000);
      alert('geolocation end')
    })

    .then( () => {
      alert('end all');
      console.log('end all');
    })    

  }

  loadScript(){
    alert('1');
    var promise = new Promise((resolve, reject) => {
          alert("inside promise");
        console.log("Async Work Complete");
          console.log('start1');
          var script = document.createElement('script');

          script.src = "https://maps.googleapis.com/maps/api/js?key=AIzaSyBtYmf_L2ESZVcnkeIHRw_uD0VQIBbFYAM&libraries=places";
          console.log('append3');
          document.head.appendChild(script); //or something of the likes
          script.onload = function () {
            console.log('resolved');
            alert('loaded script');
            resolve();
          };  
    });
    alert('return promise');
    return promise;  

  }

  initMap() {
//Implementation of initMap()
    alert('map Loaded');
  }

  getGeolocation(){
    //geoLocation implementation
  }

}

}

离子信息

cli packages: (/usr/lib/node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 7.1.0 

local packages:

    @ionic/app-scripts : 3.1.8
    Cordova Platforms  : android 6.3.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.1.1
    Node              : v8.9.4
    npm               : 5.7.1 
    OS                : Linux 4.13

Environment Variables:

    ANDROID_HOME : xxx
Misc:

    backend : pro
cli packages: (/usr/lib/node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 7.1.0 

local packages:

    @ionic/app-scripts : 3.1.8
    Cordova Platforms  : android 6.3.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.1.1
    Node              : v8.9.4
    npm               : 5.7.1 
    OS                : Linux 4.13

Environment Variables:

    ANDROID_HOME  : xxx/Sdk

Misc:

    backend : pro

0 个答案:

没有答案