我有一個使用離子框架調度本地通知的問題。TypeError:無法讀取在Object.schedule undefined的屬性'local'(ng-cordova.js:5042)
這是我角模塊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對象是不確定的。
我錯過了控制器中的東西嗎?
編輯 添加所需的插件有: 科爾多瓦插件添加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
- 嘗試: 與--stacktrace選項獲取運行堆棧跟蹤。使用--info或--debug選項運行以獲取更多日誌輸出。
我編輯了我的答案希望它有幫助! – e666