2017-11-08 3 views
0

異なるIDを持つforループで複数の通知をしようとしています。複数のローカル通知をイオニクスで作成するためのヘルプが必要2

私はコードをテストするとき、なぜ1つの通知しか再生しないのですか?他の通知は取り消されました(再生されません)。

この

は、イオンのドキュメントに基づいて、私のコード

addNotifications(){ 

    this.localNotifications.cancelAll(); 
    this.TempExamsList.forEach(e=>{ 
     let notificationTime = new Date(); 
     notificationTime.setFullYear(
     parseInt(moment(e.date,"YYYY-MM-DD").format("YYYY")), 
     parseInt(moment(e.date,"YYYY-MM-DD").format("MM"))-1, 
     parseInt(moment(e.date,"YYYY-MM-DD").format("DD"))); 
     notificationTime.setHours(parseInt(moment(e.time,"HH:mm").format("HH"))); 
     notificationTime.setMinutes(parseInt(moment(e.time,"HH:mm").format("mm"))); 
     this.localNotifications.schedule({ 
      id: new Date().getUTCMilliseconds(), 
      title: e.name, 
      text: "Location: " + e.location + " - Time: " + e.time, 
      at: notificationTime, 
      //sound: null, 
     }); 
    }) 

    this.TempTasksList.forEach(t=>{ 
     let notificationTime = new Date(); 
     notificationTime.setFullYear(
     parseInt(moment(t.date,"YYYY-MM-DD").format("YYYY")), 
     parseInt(moment(t.date,"YYYY-MM-DD").format("MM"))-1, 
     parseInt(moment(t.date,"YYYY-MM-DD").format("DD"))); 
     notificationTime.setHours(parseInt(moment(t.time,"HH:mm").format("HH"))); 
     notificationTime.setMinutes(parseInt(moment(t.time,"HH:mm").format("mm"))); 
     this.localNotifications.schedule({ 
      id: new Date().getUTCMilliseconds(), 
      title: t.name, 
      text: "Time: " + t.time, 
      at: notificationTime, 
      //sound: null, 
     }); 
    }) 
} 

答えて

0

です:

this.localNotifications.schedule([{ 
 
    id: 1, 
 
    text: 'Multi ILocalNotification 1', 
 
    sound: isAndroid ? 'file://sound.mp3': 'file://beep.caf', 
 
    data: { secret:key } 
 
    },{ 
 
    id: 2, 
 
    title: 'Local ILocalNotification Example', 
 
    text: 'Multi ILocalNotification 2', 
 
    icon: 'http://example.com/icon.png' 
 
}]);

ループ状態

this.localNotificationsArray = []; 
 
this.tempTaskList.forEach(data =>{ 
 
    this.localNotificationsArray.push({ 
 
     id: 1, 
 
     text: data.yourTask, 
 
     title: data.title, 
 
     icon: 'http://example.com/icon.png' 
 
     data: { secret:key } 
 
     } 
 
    }); 
 
}); 
 
this.localNotifications.schedule(this.localNotificationsArray);

試してみてください。おそらく動作します。 もし私があなただったら、私は通知のために非常に多くのアイテムをロードしません。一度だけ使用し、リストビューで詳細を記述してください。

あなたのミスは[]を使用して説明されています。this.localNotifications.schedule([])

関連する問題