$ cordovaLocalNotification - TypeError - 无法读取未定义

时间:2016-10-25 17:56:37

标签: ionic-framework cordova-plugins localnotification

我在离子应用程序中使用$ cordovaLocalNotification时遇到问题,下面的代码会产生错误消息 TypeError:无法读取未定义的属性'local'

try{
  if($scope.active.checked){
    $cordovaLocalNotification.schedule({
      id: 1,
      title: 'Notification',
      text: 'You are currently publishing your location.'
    }).then(function(result){
      AlertService.notify('Success', 'Successfully notified customer')
    }, function(err){
      AlertService.notify('Error', 'Failed to notify customer')
    });
  } else {
    $cordovaLocalNotification.cancel(1);
  }
}catch(err){
  AlertService.notify('Issue', err)
}

因此,在阅读了一些关于需要验证ionicPlatform.ready()并确保插件安装正确(并验证这些不是问题)的响应之后,我很遗憾。我认为这个问题是由 cordova.plugins.notification 未定义引起的,但我不确定为什么这个插件没有正确加载。

从Ionic,我有以下插件:

cordova-plugin-app-event 1.2.0 "Application Events"
cordova-plugin-camera 2.3.0 "Camera"
cordova-plugin-compat 1.0.0 "Compat"
cordova-plugin-console 1.0.4 "Console"
cordova-plugin-device 1.1.3 "Device"
cordova-plugin-geolocation 2.4.0 "Geolocation"
cordova-plugin-splashscreen 4.0.0 "Splashscreen"
cordova-plugin-statusbar 2.2.0 "StatusBar"
cordova-plugin-whitelist 1.3.0 "Whitelist"
de.appplant.cordova.plugin.local-notification 0.8.4 "LocalNotification"
ionic-plugin-keyboard 2.2.1 "Keyboard"

到目前为止,为了我自己的理智,我有:

  1. 使用 cordova插件手动安装插件添加de.appplant.cordova.plugin.local-notification
  2. 移除平台,移除插件,然后执行离子状态恢复
  3. 另外,值得注意的一件好事是我正在使用ionicView进行测试。所有/任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

事实证明,在模拟器或物理设备上模拟它可以正常工作。所以这是一个很好的学习经验,并非所有的cordova插件都在ionicView中运行