首页 > 解决方案 > OneSignal Cordova SDK handleNotificationRecieved 未触发

问题描述

我正在使用 OneSignal Cordova SDK 将警报推送到学校护理人员的手机上。一切正常,但如果手机静音,则不会播放通知声音。

所以我需要在收到推送时注入一个函数,检查手机是否静音,如果是则播放警报。

我以为我可以在“handleNotificationReceived”中注入函数,但它从未被解雇:

document.addEventListener('deviceready', function () {
window.plugins.OneSignal
.startInit("MY-APP-ID")    
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
        .handleNotificationReceived(function(jsonData) {
        window.androidVolume.getNotification(oldsuc,olderr);
        window.androidVolume.setNotification(100, false, volsuc);
        console.log('Empfange Alarm: ' + JSON.stringify(jsonData));
      })
        .endInit();
    }, false);
    function oldsuc(r){
        console.log('Altes Volumen' + r);
        localStorage.oldvol = r;
    }
    function olderr(){
        console.log('Konnte Volumen nicht abfragen');
    }
    function volsuc(r){
        vol = r;
        setTimeout(function() {
          window.androidVolume.setNotification(localStorage.oldvol, false);
        }, 5000);
    }

标签: androidcordovapush-notificationphonegaponesignal

解决方案


推荐阅读