{ "id": "121363", "key": "TIMOB-15534", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "16593", "description": "Release 4.0.0", "name": "Release 4.0.0", "archived": false, "released": true, "releaseDate": "2015-05-21" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2015-01-14T19:22:15.000+0000", "created": "2013-10-18T09:32:01.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "SupportTeam" ], "versions": [ { "id": "15593", "description": "Release 3.1.3", "name": "Release 3.1.3", "archived": true, "released": true, "releaseDate": "2013-09-18" } ], "issuelinks": [], "assignee": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2015-03-10T22:30:06.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "Adding the event listener for battery change is never called in ios 7 on iphone 4s and 5.\r\n\r\nTi.Platform.getBatteryLevel() reports current battery level from first launch of the app but never gets updated.\r\nFunctions as expected (gives 1% changes) on android\r\n\r\n{code} \r\nvar Battery = function UpdateBatteryLevel() {\r\n Titanium.Platform.batteryMonitoring = true;\r\n\r\n Titanium.Platform.addEventListener('battery', UpdateBattery);\r\n Ti.App.addEventListener('UpdateBattery', RefreshBattery);\r\n \r\n\r\n};\r\n\r\nfunction UpdateBattery(e) {\r\n var battLevel = e.level;\r\n if (Ti.Platform.osname == 'iphone') {\r\n if (battLevel > -1) {\r\n battLevel = battLevel * 100;\r\n }\r\n }\r\n\r\n Ti.App.Properties.setDouble('batterylevel', battLevel);\r\n Ti.App.fireEvent('BatteryUpdated');\r\n Ti.API.info(new Date() + ' - Battery Level Updated to ' + Ti.App.Properties.getDouble('batterylevel'));\r\n}\r\n\r\nfunction RefreshBattery() {\r\n var battLevel = Ti.Platform.getBatteryLevel();\r\n if (Ti.Platform.osname == 'iphone') {\r\n if (battLevel > -1) {\r\n battLevel = battLevel * 100;\r\n }\r\n }\r\n Ti.App.Properties.setDouble('batterylevel', battLevel);\r\n Ti.API.info(new Date() + ' - Battery Level = ' + Ti.App.Properties.getDouble('batterylevel'));\r\n}\r\n\r\n\r\n\r\nmodule.exports = Battery; \r\n{code} \r\n\r\n", "attachment": [], "flagged": false, "summary": "iOS: Battery Platform event listener doesn't work after first call", "creator": { "name": "marchief", "key": "marchief", "displayName": "Martin Williamson", "active": true, "timeZone": "Europe/London" }, "subtasks": [], "reporter": { "name": "marchief", "key": "marchief", "displayName": "Martin Williamson", "active": true, "timeZone": "Europe/London" }, "environment": "Titianium 3.2.2", "closedSprints": [ { "id": 291, "state": "closed", "name": "2015 Sprint 01 SDK", "startDate": "2015-01-03T01:00:00.000Z", "endDate": "2015-01-17T01:00:00.000Z", "completeDate": "2015-01-19T17:24:40.828Z", "originBoardId": 114 }, { "id": 272, "state": "closed", "name": "2014 Sprint 25 SDK", "startDate": "2014-12-08T22:49:31.264Z", "endDate": "2014-12-22T01:00:00.000Z", "completeDate": "2015-01-05T18:18:28.523Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "284744", "author": { "name": "gaugau3000", "key": "gaugau3000", "displayName": "gautier pialat", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Hi,\r\n\r\nAny workaround possible?\r\n\r\nImpossible to get the battery status updated ?\r\n\r\nMany tks.\r\n\r\nCan you please up/define a priority (We are building an app for divers with photo and video. Dont have the battery level on the diver dasboard on app is a blocking point (due to photo and video use a lot of battery and everything is manage by an overlay in fullScreen)) ?", "updateAuthor": { "name": "gaugau3000", "key": "gaugau3000", "displayName": "gautier pialat", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-12-17T14:38:41.000+0000", "updated": "2013-12-17T14:38:41.000+0000" }, { "id": "298988", "author": { "name": "tartantangerine", "key": "tartantangerine", "displayName": "Tim Fisher", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Same problem is batteryState - it will only return the true value from the first launch.\r\n\r\n{code}\r\n\r\nsetInterval(function(){\r\n\tTitanium.Platform.batteryMonitoring = true;\r\n\tTitanium.App.idleTimerDisabled = (Ti.Platform.batteryState == Ti.Platform.BATTERY_STATE_UNPLUGGED)?false:true;\r\n\talert(Ti.Platform.batteryState);\r\n}, 1000 * 5);\r\n\r\n{code}", "updateAuthor": { "name": "tartantangerine", "key": "tartantangerine", "displayName": "Tim Fisher", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-03-27T16:47:23.000+0000", "updated": "2014-03-27T16:48:19.000+0000" }, { "id": "300279", "author": { "name": "david.x.smith@sprint.com", "key": "david.x.smith@sprint.com", "displayName": "David Smith", "active": true, "timeZone": "America/Chicago" }, "body": "I'm interested in a fix for this bug as well. In the meantime, here is what I did to work around the issue:\r\n\r\n// Work-around for TIMOB-15534, toggle batteryMonitoring off then on to get the current batteryState.\r\nTi.Platform.batteryMonitoring = false;\r\nTi.Platform.batteryMonitoring = true;\r\n\r\nNow Ti.Platform.batteryState seems to be updated.\r\n\r\nThe Ti.Platform battery event only fires once. To work around this issue, I simply created a setInterval timer and checked Ti.Platform.batteryState every 5 seconds or so, toggling batteryMonitoring off then on each time as shown above before reading Ti.Platform.batteryState.", "updateAuthor": { "name": "david.x.smith@sprint.com", "key": "david.x.smith@sprint.com", "displayName": "David Smith", "active": true, "timeZone": "America/Chicago" }, "created": "2014-04-08T20:28:04.000+0000", "updated": "2014-04-08T20:28:04.000+0000" }, { "id": "335711", "author": { "name": "ian.wu@adtalk.com.au", "key": "ian.wu@adtalk.com.au", "displayName": "Ian Wu", "active": true, "timeZone": "Australia/Sydney" }, "body": "Great tip - thanks David...\r\nAny ideas when this will get fixed? It's 3.4.1GA already and we're now in iOS8.1.1 and still not working... Thanks is advanced for getting this fixed soon!", "updateAuthor": { "name": "ian.wu@adtalk.com.au", "key": "ian.wu@adtalk.com.au", "displayName": "Ian Wu", "active": true, "timeZone": "Australia/Sydney" }, "created": "2014-12-09T22:19:12.000+0000", "updated": "2014-12-09T22:19:12.000+0000" }, { "id": "339071", "author": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Test Case\r\n{code}\r\nvar win = Ti.UI.createWindow({backgroundColor:'white'});\r\n\r\nvar label = Ti.UI.createLabel({\r\n\ttop:50,\r\n\ttext:'Battery State - Unknkown\\nBattery Level - Unknkown'\r\n})\r\n\r\nwin.add(label);\r\n\r\nvar label2 = Ti.UI.createLabel({\r\n\tbottom:50,\r\n\ttext:'Battery State - Unknkown\\nBattery Level - Unknkown'\r\n})\r\n\r\nwin.add(label2);\r\n\r\nfunction UpdateBattery(e) {\r\n\tlabel.text = 'Battery State - '+e.state+'\\nBattery Level - '+e.level;\r\n}\r\n\r\nfunction UpdateBattery2() {\r\n\tlabel2.text = 'Battery State - '+Ti.Platform.batteryState+'\\nBattery Level - '+Ti.Platform.batteryLevel;\r\n}\r\n\r\n//Enable battery monitoring and add listener\r\nTi.Platform.batteryMonitoring = true;\r\nTi.Platform.addEventListener('battery',UpdateBattery);\r\n\r\n//Check every 3 seconds via properties\r\nsetInterval(UpdateBattery2,3000);\r\n\r\nwin.open();\r\n{code}", "updateAuthor": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2015-01-14T18:43:32.000+0000", "updated": "2015-01-14T18:43:32.000+0000" }, { "id": "339072", "author": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Pull pending\r\nmaster - https://github.com/appcelerator/titanium_mobile/pull/6568", "updateAuthor": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2015-01-14T18:45:11.000+0000", "updated": "2015-01-14T18:45:11.000+0000" }, { "id": "345626", "author": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Verified fixed using:\r\n\r\nTitanium SDK 4.0.0.v20150306095010\r\nStudio 4.0.0.201502171827\r\nCLI 3.4.2\r\nXcode 6.2\r\n\r\nWas able to see battery events fired multiple times.", "updateAuthor": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2015-03-10T22:30:06.000+0000", "updated": "2015-03-10T22:30:06.000+0000" } ], "maxResults": 8, "total": 8, "startAt": 0 } } }