我在使用离子框架安排本地通知时遇到问题。
这是我的 app.js
的角度模块angular.module('starter', ['ionic','chart.js','ngCordova'])
带控制器
.controller("ExampleController", function($scope, $ionicPlatform,$interval,$cordovaLocalNotification)
我尝试使用此方法创建通知
scheduleInstantNotification = function () {
$cordovaLocalNotification.schedule({
id: 1,
text: 'Value out of bound',
title: 'Anomaly'
}).then(function () {
alert("Instant Notification set");
});;
};
在Android设备上运行时,我收到以下错误消息:
TypeError: Cannot read property 'local' of undefined
at Object.schedule (ng-cordova.js:5042)
at scheduleInstantNotification (app.js:138)
at app.js:64
at ionic.bundle.js:56230
at Object.ready (ionic.bundle.js:2140)
at Object.ready (ionic.bundle.js:56223)
at app.js:62
at callback (ionic.bundle.js:25611)
at Scope.$eval (ionic.bundle.js:30395)
at Scope.$digest (ionic.bundle.js:30211)
我怀疑此错误来自ngCordova库,错误来自库的此代码部分
schedule: function (options, scope) { var q = $q.defer(); scope = scope || null; $window.cordova.plugins.notification.local.schedule(options, function (result) { q.resolve(result); }, scope); return q.promise; },
$ window.cordova.plugins.notification.local 对象未定义。
我是否错过了控制器中的某些内容?
修改 添加所需的插件: cordova插件添加https://github.com/katzer/cordova-plugin-local-notifications.git
在运行
时导致编译器错误ionic build android
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
> Could not find any matches for com.android.support:support-v4:+ as no versions of com.android.support:support-v4 are available.
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/support/support-v4/maven-metadata.xml
https://repo1.maven.org/maven2/com/android/support/support-v4/
https://jcenter.bintray.com/com/android/support/support-v4/maven-metadata.xml
https://jcenter.bintray.com/com/android/support/support-v4/
Required by:
:android:unspecified
答案 0 :(得分:0)
您需要添加插件:
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
按照ngcordova文件的说明:
http://ngcordova.com/docs/plugins/localNotification/
请务必在$ionicPlatform.ready
之后调用插件中的任何方法。
修改强> 使用此插件进行编译时出现错误,请务必在Android SDK Manager中安装Android支持库。