The beep does not work when the phonegap application is in the background on iOS

Im working on the iOS version of my phone navigation app. My app tracks the location of users around the walking route using GPS and alerts the user using audio (navigator.notification.beep) and tactile (navigator.notification.vibrate) feedback when they reach the location where new instructions follow.

When my application runs in the foreground, both the sound signal and the vibration light when it reaches a geographical position, but when the application pauses in the background, either by pressing the power button to turn off the screen or by pressing the house to return to the springboard, only vibration works - no beep is heard. I added debug, so I can see in the log file that the application calls navigator.notification.beep (), in the background, but there is no beep. Ive tested my application on iPhone 4S running iOS 6.3.1 and iPad 2 with iOS 5.1.1. Apparently, the iPad doesn't vibrate, but the beep sounds when the app is in the foreground, but not in the background.

  • My application uses Phonegap 2.5.0
  • Im using the latest Xcode v4.6.2 with the latest SDK for iOS 6.3.1
  • Im using beep.wav in the root directory / www
  • My .plist applications install "UIBackgroundModes" from "location" and "audio"
  • The config.xml file contains the following parameters:

    <plugin name = Value "Notification" = "CDVNotification" />

    <plugin name = Value "Media" = "CDVSound" />

    <preference name = "MediaPlaybackRequiresUserAction" value = "false" />

    <preference name = "AllowInlineMediaPlayback" value = "true" />

Any suggestions on how to fix this will be most valuable :-)

+4
source share
1 answer

In case anyone is interested in this, here is how I solved it:

I updated the phonegap Local Notifications plugin for use with Cordova 2.x. I used the plugin to provide a background beep and a telephone conversation for the front beep, putting the same sound for the telephone plug in www / beep.wav as for local notification in the resources of the iOS project in the form of 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"); } 
+2
source

Source: https://habr.com/ru/post/1482566/


All Articles