We are using the ‘cordova-plugin-background-mode’ by katzer and have been approved once by the iOS revision team after I demo a video of the app using the plugin. But when we attempted to update our app last week Apple rejected us and will not accept an other “demo video”.
Our Ionic App needs to run in the background and this cordova backgroud plugin seems to our only solution for this.
Apparently this plugin comes with an audio file at 0 volume that 'plays in the background in other words it’s ‘tricking’ or mimic native functionality to keep the app running in the background. Android seems to be ok with it but Apple sends us this.
The audio key is intended for use by apps that provide audible content
to the user while in the background, such as music player or streaming
audio apps. Please revise your app to provide audible content to the
user while the app is in the background or remove the “audio” setting
from the UIBackgroundModes key.
Obviously we can’t do that because then the core functionality of the app running in the background will not work. I guess this is what Hybrid Mobile App developers have to deal with to achieve certain native features.
Any Ionic devs out there who have figured out a work around for this?
Open the project in Xcode and go to Capabilities, make sure that “Audio, AirPlay, and Picture in Picture” is disabled under “Background Modes”. This needs to be done almost after every build… So you can either:
A. Get used to removing the tick before each release build
B. Setup a hook with a script to remove it, here’s my script:
scripts/ios_fix_audio_background.js
#!/usr/bin/env node
var fs = require("fs");
var find = require("find");
var colors = require("colors");
var path = __dirname + "/../platforms/ios/";
find.file(/\-Info\.plist$/, path, function(files) {
if(files.length > 1) {
console.log("Multiple possible plist files found".red);
process.exit(1);
} else if(files.length === 0) {
console.log("No info plist found".red);
process.exit(1);
} else {
var plistpath = files[0];
/**
* Determine app name
*/
var appname = plistpath.match(/([^\/\\]+)(\/|\\)[^\/\\]+$/)[1];
/**
* Modify plist
*/
var plist = fs.readFileSync(plistpath, "utf8");
plist = plist.replace(/\s+<string>audio<\/string>/, "");
fs.writeFile(plistpath, plist, function(err) {
if(err) {
console.log("Failed to remove Audio from Background Modes in Capabilities".red);
throw err;
} else {
console.log("Removed Audio from Background Modes in Capabilities and wrote to plist file".green);
}
});
}
});