javascript - Unable to initial cordova background mode on Ionic App -
i have ionic app metronome , has settings page toggle on / off background audio.
when loading app:
$ionicplatform.ready(function() { settingsstorageservice.getsettings().then(function(response) { $rootscope.data.appsettings = response; settimeout(function () { if ($rootscope.data.appsettings.playbackgroundaudio) { cordova.plugins.backgroundmode.enable(); } else { cordova.plugins.backgroundmode.disable(); } }, 100); }); });
i call settings factory , enable / disable background audio plugin. works fine when first loading app, when toggling setting doesn't update enabled / disabled state of plugin settings. when close down app , re open correctly takes setting affect.
when toggling setting control, call method in settingsstorageservice factory.
inside of method re run if statement:
function getsettings() { return $q.when(_db.alldocs({ include_docs: true})).then(function(docs) { _settings = docs.rows.map(function(row) { return row.doc; }); if (_settings.length) { $rootscope.data.appsettings = _settings[0]; // try reset plugin alert($rootscope.data.appsettings.playbackgroundaudio); settimeout(function () { if ($rootscope.data.appsettings.playbackgroundaudio) { cordova.plugins.backgroundmode.enable(); } else { cordova.plugins.backgroundmode.disable(); } }, 100); return _settings[0]; } else { return _defaultsettings; } }); }
the alert correctly shows changed state, plugin doesn't seem change settings until closing , opening app. there else need re initialise plugin?
Comments
Post a Comment