Beep not working when phonegap app is in background on iOS

纵然是瞬间 提交于 2019-12-04 09:55:12

In case anyone else in interested, here’s how I solved this:

I updated the Local Notifications phonegap plugin for use with Cordova 2.x. I used the plugin to provide the background beep and phonegap for the foreground beep by placing the same sound for phonegap in www/ as beep.wav as for the local notification in the iOS project Resources as beep.caf.

function doBeep(){
  cordova.require('cordova/plugin/localnotification').add(
    function(){
      console.log("Successfully added local notification");
    },
    function(){
      console.error("Error adding local notification");
    },{
      date: new Date(new Date().getTime()),
      repeat:'',
      message: '', // No message so just beep
      hasAction: true,
      badge: 0,
      id: '1',
      background:'background',
      foreground:'running',
      sound: 'beep.caf'
    }
  );
}

function running(){
  console.log("Running in the foreground so use a phonegap notification");
  navigator.notification.beep();
}

function background(){
  console.log("Running in the background so an iOS local notification will be used");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!