Project: titanium
Issue TIMOB-15534: iOS: Battery Platform event listener doesn't work after first call
Adding the event listener for battery change is never called in ios 7 on iphone 4s and 5. Ti.Platform.getBatteryLevel() reports current battery level from first launch of the app but never gets updated. Functions as expected (gives 1% changes) on android {code} var Battery = function UpdateBatteryLevel() { Titanium.Platform.batteryMonitoring = true; Titanium.Platform.addEventListener('battery', UpdateBattery); Ti.App.addEventListener('UpdateBattery', RefreshBattery); }; function UpdateBattery(e) { var battLevel = e.level; if (Ti.Platform.osname == 'iphone') { if (battLevel > -1) { battLevel = battLevel * 100; } } Ti.App.Properties.setDouble('batterylevel', battLevel); Ti.App.fireEvent('BatteryUpdated'); Ti.API.info(new Date() + ' - Battery Level Updated to ' + Ti.App.Properties.getDouble('batterylevel')); } function RefreshBattery() { var battLevel = Ti.Platform.getBatteryLevel(); if (Ti.Platform.osname == 'iphone') { if (battLevel > -1) { battLevel = battLevel * 100; } } Ti.App.Properties.setDouble('batterylevel', battLevel); Ti.API.info(new Date() + ' - Battery Level = ' + Ti.App.Properties.getDouble('batterylevel')); } module.exports = Battery; {code}
Story points: 5