Beep not working when phonegap app is in background on iOS - ios

I’m working on the iOS version of my phonegap-based navigation app. My app tracks the user’s location around a walk route using GPS and alerts the user using audio (navigator.notification.beep) and tactile (navigator.notification.vibrate) feedback when they reach a location at which there’s new instructions for them to follow.
When my app is running in the foreground, both the audible beep and the vibration fire on reaching the geographic location but when the app is paused in the background, either by pressing the power button to turn the screen off or pressing the home button to return to the springboard, only the vibration works - the beep is not audible. I’ve added debug so I can see in the log file that the app is calling navigator.notification.beep() while in the background but the beep sound isn't made. I’ve tested my app on an iPhone 4S running iOS 6.3.1 and iPad 2 running iOS 5.1.1. Obviously the iPad doesn’t vibrate but the beep works while the app is in the foreground but not when in the background.
My app is using Phonegap 2.5.0
I’m using latest Xcode v4.6.2 with latest SDK for iOS 6.3.1
I’m using a beep.wav in the /www root
My app’s .plist sets “UIBackgroundModes” of “location” and “audio”
My config.xml contains the settings:
<plugin name="Notification" value="CDVNotification" />
<plugin name="Media" value="CDVSound" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
<preference name="AllowInlineMediaPlayback" value="true" />
Any suggestions how to fix this would be most appreciated :-)

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");
}

Related

iOS 13 webaudio is totally broken for html audio elements within a webview

I'm building a mobile game using cordova, using wkwebview, and I'm having a major issue with audio not working on iOS 13 (specifically iPadOS 13.2.2). I have several html audio elements connected to an AudioContext, and when I play one after the context has been resumed, there are no js errors and everything looks good from the js side. However, it doesn't play any sound, and on the native iOS side, it throws this error:
2019-11-15 18:27:09.610800-0500 MyApp[9045:99562] [assertion] Error acquiring assertion: <NSError: 0x2811ddfe0; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
userInfo = {
RBSAssertionAttribute = <RBSLegacyAttribute: 0x111048cf0; requestedReason: MediaPlayback; reason: MediaPlayback; flags: PreventTaskSuspend | PreventTaskThrottleDown | WantsForegroundResourcePriority>;
}
}
2019-11-15 18:27:09.610840-0500 MyApp[9045:99562] [ProcessSuspension] 0x108ee7138 - ProcessAssertion() PID 9045 Unable to acquire assertion for process with PID 9045
2019-11-15 18:27:09.610894-0500 MyApp[9045:99269] [ProcessSuspension] 0x108ee7138 - ProcessAssertion::processAssertionWasInvalidated()
I've tried adding the "Audio, AirPlay, and Picture in Picture" and "Background processing" flags in the Background Modes tab of xcode, but they had no effect. Other things to note: it plays audio in the simulator even though it still throws the error, but fails to play on an actual device. Also, audio does play correctly using AudioBuffer's, it's just Audio elements that are affected. Unfortunately, I can't use AudioBuffers for my soundtrack because they're only designed for short sounds, and take way too long to load for full length songs.
I've filed this as a webkit bug: https://bugs.webkit.org/show_bug.cgi?id=204261
Has anyone been able to get html audio working on iOS 13, or know any workarounds?
Same problem, use WKWebView and audio in background stops after 30 seconds. Ticking "Audio, AirPlay, and Picture in Picture" and "Background processing" flags in the Background Modes tab of X-Code, had no effect. In iOS 12 everything worked correctly, I do not understand that is a problem of the new iOS 13 system or a new Apple company policy.
Is nothing specified or changed in their documentation about IOS 13 and audio in background (https://developer.apple.com/documentation/avfoundation/media_assets_playback_and_editing/creating_a_basic_video_player_ios_and_tvos/enabling_background_audio).
At my question via Apple Developer Support I still haven't answered.
...if anyone can answer us about this problem or help us. Thank you in advance.
I had the same issue, I solved adding these to config.xml:
<preference name="AllowInlineMediaPlayback" value="true" />
This allows media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls.
For more details read:
https://cordova.apache.org/docs/en/5.1.1/guide/platforms/ios/config.html

Local notification not working on IOS - ionic

I added local notification in my ionic application using the below code and was working good.but there is an issue on iOS
https://ionicframework.com/docs/native/local-notifications/
this.localNotifications.schedule({
id: 1,
text: 'Single ILocalNotification',
sound: isAndroid? 'file://sound.mp3': 'file://beep.caf',
data: { secret: key }
});
This is not working on IOS ,if we open application from background.
Error replicate steps.
1.Open applicaton
2.Minimize application in the background
3.Open application from background.
4.After this the notification was not showing on the status bar,but we can here the notification sound

ionic2 - embed youtube video play with no sound in iOS v10

I embed a youtube video in ionic2 app:
Page2.ts:
import {SafeResourceUrl, DomSanitizer} from '#angular/platform-browser';
export class Page2 {
url: SafeResourceUrl;
constructor(public navCtrl: NavController,
public navParams: NavParams,
sanitizer: DomSanitizer) {
this.url = sanitizer.bypassSecurityTrustResourceUrl('https://www.youtube.com/embed/XHCVWWsQmUs');
}
}
Page2.html:
<iframe height="190" onload="this.width=screen.width" [src]="url" frameborder="0" ></iframe>
And add some preferences for configurations:
config.xml:
<allow-navigation href="*://*.youtube.com/*" />
<allow-navigation href="*youtube*" />
<allow-navigation href="*ytimg*" />
<preference name="AllowInlineMediaPlayback" value="true" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
It works fine on android device but no sound in iOS. I am getting this error in XCode console:
2016-11-08 10:06:10.648528 app[1066:438304] ERROR Internal navigation
rejected - not set for url='about:blank'
Not sure if it is the issue affect the sound.
How can I resolve this? Could it be the bug from Ionic or Cordova?
I see that this is an older post but thought I'd try to revive it to see if anyone else might have a viable solution.
I have a similar issue with embedded YouTube video in an ionic v1 project. Note that I am using the AngularJS module to embed Youtube videos ng-youtube-embed found here:
https://github.com/ArunMichaelDsouza/ng-youtube-embed
Everything works as expected except for the audio on iOS. If the device is toggled to silent mode (with the hardware silent toggle button) the audio is muted. When the ringer is switched back on (hardware toggle) the audio plays back as expected. In researching this issue I keep coming across the that it is a problem with Cordova. That the audio is treated as a UI sound/sound effect and will not playback when the silent switch is on (the ringer off).
The only solution I have come across is half baked at best and have read some posts noting that their app was rejected by Apple because of the hackish solution (a plugin that forces a background audio sound). Otherwise it may be "That's just the way it is". :(

No HTML5 audio on (iOS8) device in cordova/phonegap app

I have a cordova app that was using media plugin for audio playback, but then it got broken with iOS8, because of this bug. I thought I will just use HTML5 audio (concretely audio5.js) as a workaround. Everything works nice in the simulator but when tested on the iPad, there is no sound. There is also no error reported it just looks as the sound is turned off.
For the testing I made cordova app with just plain example from the audio5.js github repository and I also tried with examples from two similar libraries audio.js and sound.js.
The result is the same, examples work in simulator and also from the web on mobile Safari on the device, but on the device inside cordova there is no sound.
I also included this two lines in the config.xml file
<preference name="AllowInlineMediaPlayback" value="true"/>
<preference name="MediaPlaybackRequiresUserAction" value="false"/>
without success.
I'm using cordova cli version: 3.6.3-0.2.13
EDIT:
It seems that iOS update 8.1.2 resolved original problem bug, so I recomend using Media plugin for audio on iOS .
I managed to get sound on the device with WKWebView which is at the moment not yet available in core cordova because there are some bugs. A workaround is a WKWebView plugin that is described by DevGirl here.
Using WKWebView created a problem for audio5.js when playing multiple sounds one after another where next sound is triggered by play "ended" of previous sound. I couldn't fix the issue, so I decided to try soundmanager2.js which worked with out the problem.
I still have a problem with playing sounds which are not inside www directory (sounds are downloaded to the device and are not included with the app), but this is I think another issue not related to the this question.

Phonegap iOS with Geolocation in Background

I have read some of the discussions on geolocation in background on PhoneGap, but am still having problems.
I'm working on an application that uses geolocation services.
On IOS when application is in foreground all works fine. When the application goes to background (after around 30-40 minutes) however the geocoding stops working and I don't get the change position event anymore. During the period in background the application successfully JSON's a time stamp and lng/lat every few seconds to my remote server so I know it's working during that limited period.
My configuration is:
Frame work: PhoneGap 2.5
Devices: iOS (tested on 4, 4s & 5 iPhone & iPad4)
iOS Version: 7.0.4
Xcode: Version 5.0.2 (5A3005)
Plugin:
PowerManagement Plugin for Cordova (2.0+)
by Wolfgang Koller - GOFG Sports Computer
https://github.com/purplecabbage/phonegap-plugins/tree/master/iOS/PowerManagement
startWatch Function:
function onDeviceReady() {
startWatch();
function startWatch() {
var options = { enableHighAccuracy: true, timeout: 3100, maximumAge: 0 };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
timerID = setInterval ( updateLocation, 3000 );
}
.
.
App-info plist Includes:
"App registers for location updates" under "Required background modes"
&
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
config.xml includes:
<plugin name="PowerManagement" value="PowerManagement" />
Questions:
I was wondering is there a way to ensure JavaScript in PhoneGap runs continually when the app is in the background?
Do I need to set Wakelock acquired/ release to ensure the Powermanagement plugin work efficiently in iOS?
Could someone suggest a different plugin maybe or config/code I may have missed?
Cheers,
Wayne Gardner
Sydney Australia
Try out mine. Works great for iOS and Android
The plugin has a debug mode where it emits sounds for its life-cycle events (location change, exit stationary-region, and more) which is great for getting instant feedback while field-testing.
https://github.com/transistorsoft/cordova-background-geolocation-lt
I'm not sure but maybe IOS is like Android for this function : Creating an Android Service with Phonegap? (Have phonegap app run even when closed)
So, Javascript will stop when app goes in background or a few sec(or min) after.
Moreover, PowerManagement isn't the solution. PowerManagement allows you to tell the OS : "Hey guy, I have an which need to run even if the phone is lock, so please don't turn off the CPU (or Screen) when I lock the phone.
Maybe try this (only for IOS > 5 and WP8) : https://github.com/katzer/cordova-plugin-background-mode
I'm a IOS pro, I'm an Android Pro and I use Cordova and this plugin (PowerManagement) and it doesn't do what you think.
I hope I help you.
Coco

Resources