{ "id": "117528", "key": "TIMOB-14658", "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": "15646", "description": "2013 Sprint 18", "name": "2013 Sprint 18", "archived": true, "released": true, "releaseDate": "2013-09-06" }, { "id": "15690", "description": "2013 Sprint 18 API", "name": "2013 Sprint 18 API", "archived": true, "released": true, "releaseDate": "2013-09-06" } ], "resolution": { "id": "5", "description": "All attempts at reproducing this issue failed, or not enough information was available to reproduce the issue. Reading the code produces no clues as to why this behavior would occur. If more information appears later, please reopen the issue.", "name": "Cannot Reproduce" }, "resolutiondate": "2013-08-27T09:23:31.000+0000", "created": "2013-07-24T10:28:10.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "ios7", "iphone" ], "versions": [ { "id": "15478", "description": "Release 3.1.1", "name": "Release 3.1.1", "archived": true, "released": true, "releaseDate": "2013-06-17" } ], "issuelinks": [ { "id": "30383", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "outwardIssue": { "id": "115799", "key": "TIMOB-14182", "fields": { "summary": "iOS7: Update SDK to support building/running apps for iOS 7", "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" } }, "priority": { "name": "High", "id": "2" }, "issuetype": { "id": "6", "description": "gh.issue.epic.desc", "name": "Epic", "subtask": false } } } }, { "id": "31526", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "inwardIssue": { "id": "117459", "key": "TIMOB-14617", "fields": { "summary": "iOS7: Implement the new backgrounding techniques", "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" } }, "priority": { "name": "High", "id": "2" }, "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "subtask": false } } } } ], "assignee": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2017-03-31T20:31:33.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": "Since iOS 7 beta 3, using a background service with a setTimeout poll time, no longer runs after 1 iteration, after that it just seems to stop.\r\n\r\n*Global that initiates the service*\r\n{code:javascript}\r\nvar service;\r\n\r\nif (Titanium.Platform.name == 'iPhone OS'){\r\n\t// Globe event handelers\r\n\tTi.App.addEventListener('pause', function(e){ \r\n\t\tif (Ti.App.Properties.getBool('track')) {\r\n\t\t\tservice = Ti.App.iOS.registerBackgroundService({url:'/service/bg.js'});\t\r\n\t\t}\r\n\t});\r\n\t\t\t\r\n\t// Stop background service on launch.\r\n\tTi.App.addEventListener('resume', function(e){\r\n\t\t\r\n\t\tif (service != null) {\r\n\t\t\tservice.stop();\r\n\t\t\tservice.unregister();\r\n\t\t};\r\n\t});\r\n};\r\n{code}\r\n\r\n*bg.js*\r\n{code:javascript}\r\n// Background service script\r\n// NOTE: Runs in background when enabled by user to track device and report back to ETMS system.\r\n// This is for use by company security departments to ensure safety of user.\r\n\r\n\r\n\tif (!Ti.Geolocation.locationServicesEnabled) {\r\n\t\tTi.App.iOS.scheduleLocalNotification({\r\n\t\t alertBody: 'Location services are not enabled.',\r\n\t\t date:new Date(new Date().getTime() + 1000) // 1 second after unregister\r\n\t\t}); \r\n\t}\r\n\t\t\r\n\t//var tracking = require('business/tracking');\r\n\t\r\n\tvar lastTrackDate = 0;\r\n\tvar doTrack = false;\r\n\t\r\n\tfunction track() {\t\r\n\t\t\ttrackGPS('track');\r\n\t\t\tlastTrackDate = new Date().getTime();\r\n\t\t\tsetTimeout(track, Ti.App.Properties.getInt('trackingpolltime'));\r\n\t};\r\n\ttrack();\r\n\r\n\tvar nowTime;\r\n\tvar stayaliveInerval = 311000;\r\n\tvar nextstayalivepoll;\r\n\tfunction stayalive() {\r\n\t\tnowTime = new Date().getTime();\r\n\t\tif (lastTrackDate + stayaliveInerval <= nowTime) {\t\r\n\t\t\ttrackGPS('update');\r\n\t\t}\r\n\t\tnextstayalivepoll = (nowTime - lastTrackDate) > stayaliveInerval ? stayaliveInerval : stayaliveInerval - (nowTime - lastTrackDate);\r\n\t\tTi.API.info(new Date() + ' - GPS Stay Alive:' + nextstayalivepoll);\r\n\t\tsetTimeout(stayalive, nextstayalivepoll);\r\n\t}\r\n\tstayalive();\r\n\t\r\n\t\r\n\t// Event listener for GPS\r\n\tfunction trackGPS(trackType)\r\n\t{\r\n\t\tif (trackType == 'track') {\r\n\t\t\tdoTrack = true;\r\n\t\t}\r\n\t\telse {\r\n\t\t\tdoTrack = false;\r\n\t\t};\r\n\t\t\r\n\t\tTi.Geolocation.addEventListener('location', getPosition);\t\t\r\n\t};\r\n\t\r\n\t\r\n\tfunction getPosition(e) {\r\n\t if(e.error){\r\n\t \tTi.API.info(new Date() + ' - GPS error');\r\n\t }\r\n\t else {\r\n\t \tTi.Geolocation.purpose = \"Determine device location on users request.\";\r\n\t \tTi.Geolocation.accuracy = Ti.Geolocation.ACCURACY_HIGH;\r\n\t\t Ti.Geolocation.distanceFilter = 0;\r\n\t\t \r\n\t\t Ti.Geolocation.getCurrentPosition(function(e){\r\n\t\t if(e.error){\t\r\n\t\t Ti.API.info(new Date() + ' - GPS error');\r\n\t\t }\r\n\t\t else {\r\n\t\t\t //Get the GPS goods\r\n\t\t\t var longitude = e.coords.longitude;\r\n\t\t\t var latitude = e.coords.latitude;\r\n\t\t\t var altitude = e.coords.altitude;\r\n\t\t\t var accuracy = e.coords.accuracy;\r\n\t\t\t var timestamp = e.coords.timestamp;\r\n\t\t\t \r\n\t\t\t if (accuracy < 50) {\r\n\t\t\t \tTi.API.info(new Date() + ' - GPS accuracy good, background event listener:' + e.coords.accuracy);\r\n\t\t\t\t\t\t\r\n\t\t\t\t\tif (doTrack == true) {\r\n\t\t\t\t\t\tTi.API.info(new Date() + ' - Contacting web service');\r\n\t\t\t\t\t\tSendTrackingInfo(e.coords.latitude, e.coords.longitude);\r\n\t\t\t\t\t}; \r\n\t\t\t\t\t\r\n\t\t\t\t\tTitanium.Geolocation.removeEventListener('location', getPosition);\t\r\n\t\t\t };\r\n\t\t };\r\n\t\t });\r\n\t }; \r\n\t};\r\n\t\r\n\tvar client = null;\r\n\t\r\n\tfunction SendTrackingInfo(latitude, longitude) {\r\n\t\r\n\t \tclient = Ti.Network.createHTTPClient({\r\n\t\t onload : function(e) {Ti.API.info(new Date() + ' - Background web service conected');},\r\n\t \t\tonerror : function(e) {Ti.API.info(new Date() + ' - Background web service NOT conected');},\r\n\t \t \ttimeout : 28000\r\n\t\t});\r\n\t\t\r\n\t\t// Prepare and send the connection.\r\n\t\tclient.open(\"GET\", \r\n\t\t\t//'http://192.168.0.23/tracking/TrackingService/Track?deviceid=' +\r\n\t\t//\tTi.App.Properties.getString('deviceid') +\r\n\t\t//\t'&longitude='+longitude+'&latitude='+latitude+'&clientid=' +\r\n\t\t//\tTi.App.Properties.getString('clientid') +\r\n\t\t//\t'&trackingtypeid=1');\r\n\t\t\r\n\t//\tclient.send();\r\n\r\n\talert('Service Called');\r\n\r\n\t};\r\n{code}", "attachment": [], "flagged": false, "summary": "iOS7: Background Service no longer functions", "creator": { "name": "anvil_martin", "key": "anvil_martin", "displayName": "Martin Williamson", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "anvil_martin", "key": "anvil_martin", "displayName": "Martin Williamson", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "iPhone, Titanium 3.1.1 GA", "comment": { "comments": [ { "id": "263000", "author": { "name": "dsefton", "key": "dsefton", "displayName": "Daniel Sefton", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Hi Martin,\r\n\r\nPlease can you provide a reproducible test case that we can drop into an app.js and run?\r\n\r\nThanks!", "updateAuthor": { "name": "dsefton", "key": "dsefton", "displayName": "Daniel Sefton", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-07-24T18:29:44.000+0000", "updated": "2013-07-24T18:29:44.000+0000" }, { "id": "263143", "author": { "name": "anvil_martin", "key": "anvil_martin", "displayName": "Martin Williamson", "active": true, "timeZone": "America/Los_Angeles" }, "body": "here you go.\r\n\r\n[moved to description]", "updateAuthor": { "name": "dsefton", "key": "dsefton", "displayName": "Daniel Sefton", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-07-25T13:25:18.000+0000", "updated": "2013-07-25T17:57:12.000+0000" }, { "id": "268322", "author": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Could not reproduce.\r\n\r\nIOS7 DP5", "updateAuthor": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2013-08-27T09:23:31.000+0000", "updated": "2013-08-27T09:23:31.000+0000" }, { "id": "269216", "author": { "name": "anvil_martin", "key": "anvil_martin", "displayName": "Martin Williamson", "active": true, "timeZone": "America/Los_Angeles" }, "body": "After upgrading to iOS 7 beta 6 and using the latest release of titanium, this appears to function but not as intended, while the device is awake it seems to work on or before the interval, however with the screen off it does not report after 1-2 iterations, however it then sends a load of reports once the device is awake again (screen on and unlocked) as if it was caching them for later, providing the interval has passed several times", "updateAuthor": { "name": "anvil_martin", "key": "anvil_martin", "displayName": "Martin Williamson", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-02T13:13:57.000+0000", "updated": "2013-09-02T13:13:57.000+0000" }, { "id": "269299", "author": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "body": "[~anvil_martin] I wonder if that's related to TIMOB-14617?", "updateAuthor": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-03T17:10:12.000+0000", "updated": "2013-09-03T17:10:12.000+0000" }, { "id": "269673", "author": { "name": "anvil_martin", "key": "anvil_martin", "displayName": "Martin Williamson", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Ingo Muschenetz - I think it is, I am doing a lot of investigation into this at the moment is this breaks our core functionality (a tracking application that runs in the background).\r\nI have yet to produce any solid or reproducible results, even tracking at one minute intervals as soon as the screen goes off it stops tracking and doesn't always seem to resume on wake up or after any set amount of time, I am beginning to think that there have been some changes to the implementation of the distance filtering as well.\r\n\r\nAfter Installing and pointing Titanium at Xcode 5 DP 6, the simulator runs the code perfectly and doesn't die off when locked, however on the device (iphone 5 iOS 7 beta 6) the background service stops after 2 iterations.\r\nI also cannot seem to attach it to the debugger either, both just sit on the network waiting for a connection so, any suggestions on debugging it on the device?", "updateAuthor": { "name": "anvil_martin", "key": "anvil_martin", "displayName": "Martin Williamson", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-05T08:39:22.000+0000", "updated": "2013-09-05T15:52:34.000+0000" }, { "id": "269914", "author": { "name": "anvil_martin", "key": "anvil_martin", "displayName": "Martin Williamson", "active": true, "timeZone": "America/Los_Angeles" }, "body": "After a lot more investigation, it turns out that as of iOS 7, background services are killed after 3 minutes, you have to use the new methods they have implemented to run, we are changing to location based (using distance filter) with a keep alive function for now which seems to work", "updateAuthor": { "name": "anvil_martin", "key": "anvil_martin", "displayName": "Martin Williamson", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-06T14:34:42.000+0000", "updated": "2013-09-06T14:34:42.000+0000" }, { "id": "416529", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket with reference to the above comment.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-03-31T20:31:33.000+0000", "updated": "2017-03-31T20:31:33.000+0000" } ], "maxResults": 10, "total": 10, "startAt": 0 } } }