Uncaught (in promise): cordova_not_available in Ionic 2

前端 未结 8 1484
情书的邮戳
情书的邮戳 2020-12-13 12:33

When I\'m running my Ionic app with ionic serve -l command, get following error message:

Runtime Error

Unca

8条回答
  •  心在旅途
    2020-12-13 13:13

    Cordova is only accessible when you run your app on a real device. When you test your app in the browser, it cannot access those native plugins.

    You can check if you are on a real device or a browser like that:

    if (this.platform.is('cordova')) {
      // You are on a device, cordova plugins are accessible
    } else {
      // Cordova not accessible, add mock data if necessary
    }
    

    This will only help you test the parts of your app that don't rely on cordova plugins. To really test your app, you need to run it on a device or in the emulator.

提交回复
热议问题