タイトルの通り、Cordovaのプラグインを使ってローカル通知の機能を実装したいのですが上手くいきません。
【やりたいこと】
・カウントダウンタイマーが0になった時に都度、ローカル通知でお知らせする
【現状】
・ビルドして最初のテスト時には上手くできるものの、2回目以降は機能しない。
・アプリを終了し、再度テストしてみても同じく機能しない。
【ソースコード】
main.js
// カウントダウンタイマー function count() { if ( time === 0 ) { // タイマーが0になった時の処理 sec.innerHTML = "00"; min.innerHTML = "00"; clearInterval( counter ); playBeep(); // アラート音を呼び出す cordova.plugins.notification.local.schedule({ id: 1, text: "タイマーが終了しました" }); } else { // タイマーのカウントダウン表示 time -= 1; var displayMin = Math.floor( time / 60 ); var displaySec = time % 60; if (displayMin < 10 ) displayMin = "0" + displayMin; if (displaySec < 10 ) displaySec = "0" + displaySec; min.innerHTML = displayMin; sec.innerHTML = displaySec; } } // アラート音 function playBeep() { navigator.notification.beep(4); navigator.notification.vibrate(5000); }
index.js
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // 'load', 'deviceready', 'offline', and 'online'. bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, // deviceready Event Handler // // The scope of 'this' is the event. In order to call the 'receivedEvent' // function, we must explicitly call 'app.receivedEvent(...);' onDeviceReady: function() { app.receivedEvent('deviceready'); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id); } }; app.initialize();
index.html
<html> 〜 一部省略 〜 <script type="text/javascript" src="js/main.js"></script> <script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="js/index.js"></script> </body> </html>
ビルドして最初のアプリ立ち上げの実行時のみローカル通知が実行されるといった状態です。
分かる方ご教授頂けますと幸いです。
どうぞ宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/25 15:36