背景地理位置插件不适用于Android版本

时间:2018-01-22 10:44:45

标签: android cordova ionic2 ionic3 ionic-native

我有一个安装了BackgroundGeolocation插件的Ionic应用程序。当我使用ionic cordova run android运行应用程序时,该应用程序运行正常,但是当我进行构建并在手机上手动安装时,我在启动应用程序时出现此错误:

Native: tried calling BackgroundGeolocation.configure, but the BackgroundGeolocation plugin is not installed

这是我的packaje.json文件:

 {
   "name": "cm-mobile",
   "version": "0.0.1",
   "author": "Ionic Framework",
   "homepage": "http://ionicframework.com/",
   "private": true,
   "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "5.0.3",
    "@angular/compiler": "5.0.3",
    "@angular/compiler-cli": "5.0.3",
    "@angular/core": "5.0.3",
    "@angular/forms": "5.0.3",
    "@angular/http": "5.0.3",
    "@angular/platform-browser": "5.0.3",
    "@angular/platform-browser-dynamic": "5.0.3",
    "@ionic-native/background-geolocation": "^4.5.2",
    "@ionic-native/background-mode": "^4.5.2",
    "@ionic-native/barcode-scanner": "^4.5.2",
    "@ionic-native/battery-status": "^4.5.2",
    "@ionic-native/camera": "^4.5.2",
    "@ionic-native/core": "^4.5.2",
    "@ionic-native/file": "^4.5.2",
    "@ionic-native/file-transfer": "^4.5.2",
    "@ionic-native/geolocation": "^4.5.2",
    "@ionic-native/launch-navigator": "^4.5.2",
    "@ionic-native/push": "^4.5.2",
    "@ionic-native/splash-screen": "4.4.0",
    "@ionic-native/status-bar": "^4.4.0",
    "@ionic/storage": "2.1.3",
    "@types/leaflet": "^1.2.5",
    "cordova-android": "6.3.0",
    "cordova-plugin-actionsheet": "^2.3.3",
    "cordova-plugin-background-mode": "^0.7.2",
    "cordova-plugin-battery-status": "^2.0.1",
    "cordova-plugin-camera": "^4.0.1",
    "cordova-plugin-device": "^1.1.4",
    "cordova-plugin-dialogs": "^2.0.1",
    "cordova-plugin-file": "^5.0.0",
    "cordova-plugin-file-transfer": "^1.7.0",
    "cordova-plugin-geolocation": "^4.0.1",
    "cordova-plugin-ionic-webview": "^1.1.16",
    "cordova-plugin-mauron85-background-geolocation": "^2.3.3",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-statusbar": "^2.4.1",
    "cordova-plugin-whitelist": "^1.3.1",
    "ionic-angular": "3.9.2",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionicons": "3.0.0",
    "leaflet": "^1.2.0",
    "phonegap-plugin-barcodescanner": "^7.0.1",
    "phonegap-plugin-push": "^2.1.2",
    "rxjs": "5.5.2",
    "sw-toolbox": "3.6.0",
    "uk.co.workingedge.phonegap.plugin.launchnavigator": "^4.1.3",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.6",
    "typescript": "2.4.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "ionic-plugin-keyboard": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-mauron85-background-geolocation": {
        "GOOGLE_PLAY_SERVICES_VERSION": "11.0.1",
        "ICON": "@mipmap/icon",
        "SMALL_ICON": "@mipmap/icon",
        "ACCOUNT_NAME": "@string/app_name",
        "ACCOUNT_LABEL": "@string/app_name",
        "ACCOUNT_TYPE": "$PACKAGE_NAME.account",
        "CONTENT_AUTHORITY": "$PACKAGE_NAME"
      },
      "phonegap-plugin-push": {
        "FCM_VERSION": "11.0.1"
      },
      "cordova-plugin-file-transfer": {},
      "cordova-plugin-file": {},
      "cordova-plugin-geolocation": {},
      "cordova-plugin-camera": {},
      "cordova-plugin-background-mode": {},
      "phonegap-plugin-barcodescanner": {},
      "cordova-plugin-battery-status": {},
      "uk.co.workingedge.phonegap.plugin.launchnavigator": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-datecs-printer": {}
    },
    "platforms": [
      "android"
    ]
  }
}

我有什么不对的,或者来自ionic-native或插件的错误?

2 个答案:

答案 0 :(得分:1)

发生在我身上的原因是我没有从正确的位置调用该函数(我是从服务而不是从app.component.ts调用它的。)

guide指出:

  

BackgroundGeolocation必须在app.ts 和...

之内称为

答案 1 :(得分:0)

问题似乎在最新版本中得到解决,如下所示: https://github.com/ionic-team/ionic-native/issues/258

  

当ionic-native无法找到包装器定义中提供的pluginRef时,会发生插件未安装错误。 pluginRef设置为plugins.backgroundGeoLocation而不是backgroundGeolocation