{ "id": "163588", "key": "TIMOB-23972", "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": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2016-10-02T13:05:36.000+0000", "created": "2016-10-01T20:28:59.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "allowsBackgroundLocationUpdates", "backgroundservice", "ios", "ipass1", "location" ], "versions": [], "issuelinks": [], "assignee": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2018-08-06T17:37:01.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": "Steps to Reproduce.\r\n\r\n1. Create a classic project.\r\n2. paste the following code to the corresponding file.\r\n{code:title=app.js}\r\nvar win = Ti.UI.createWindow({\r\n\ttitle : 'Background Services Example',\r\n\tbackgroundColor : '#4186cd',\r\n\tmodal : true\r\n});\r\n\r\n// Create a Button.\r\nvar bgService = Ti.UI.createButton({\r\n\ttitle : 'StartService',\r\n\theight : Ti.UI.SIZE,\r\n\twidth : Ti.UI.SIZE,\r\n\ttop : 20,\r\n\r\n});\r\n\r\n\r\nfunction bgServiceStart() {\r\n\tTi.API.info('Registering background services');\r\n\tvar service = Ti.App.iOS.registerBackgroundService({\r\n\t\turl : 'bgservice.js'\r\n\t});\r\n\tTi.API.info('*** Press home button to pause application ***');\r\n}\r\n\r\n// Listen for click events.\r\nbgService.addEventListener('click', function() {\r\n\tbgServiceStart();\r\n\r\n\talert('click bg service');\r\n});\r\n\r\n// Add to the parent view.\r\nwin.add(bgService);\r\n\r\nwin.open();\r\n\r\n\r\n{code}\r\n{code:title=bgservice.js}\r\nTi.API.info('bg-service1: service page');\r\n\r\nif (Ti.Platform.name == \"iPhone OS\" && parseInt(Ti.Platform.version.split(\".\")[0]) >= 8) {\r\n\tTi.App.iOS.registerUserNotificationSettings({\r\n\t\ttypes : [Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT, Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND, Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE]\r\n\t});\r\n}\r\n\r\nfunction pushData(latLong) {\r\n\r\n\tvar curNotif = Ti.App.iOS.scheduleLocalNotification({\r\n\t\talertBody : latLong,\r\n\t\tdate : new Date(new Date().getTime() + 1000)\r\n\t});\r\n}\r\n\r\nfunction getCoords() {\r\n\r\n\tif (Ti.Geolocation.locationServicesEnabled) {\r\n\t\tTi.Geolocation.allowsBackgroundLocationUpdates = true;\r\n\t\tTi.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;\r\n\t\tTi.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;\r\n\t\tTi.Geolocation.addEventListener('location', function(e) {\r\n\t\t\tif (e.error) {\r\n\t\t\t\talert('Error: ' + e.error);\r\n\t\t\t} else {\r\n\t\t\t\tTi.API.info(\"value=\" + e.coords);\r\n\t\t\t\tpushData(e.coords.latitude + '\\n' + e.coords.longitude);\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n}\r\n\r\nsetInterval(function() {\r\n\tgetCoords();\r\n\r\n}, 10000);\r\n\r\n{code}\r\n{code:title=tiapp.xml}\r\nUIBackgroundModes\r\n\r\nlocation\r\n\r\nNSLocationAlwaysUsageDescription\r\nSpecify the reason for accessing the user's location information.\r\nThis appears in the alert dialog when asking the user for permission to\r\naccess their location.\r\nUISupportedInterfaceOrientations~iphone\r\n{code}\r\n3. Run that code to the device\r\n4. It does not work more that 10 minutes even below 10 minutes and don't show blue bar.\r\n5. It should work more that 10 minutes and show blue bar as well since I have added UIBackgroundModes key \r\n- http://docs.appcelerator.com/platform/latest/#!/guide/tiapp.xml_and_timodule.xml_Reference-section-29004921_tiapp.xmlandtimodule.xmlReference-UIBackgroundModes", "attachment": [], "flagged": false, "summary": "iOS: BgService more than 10 minutes and show blue bar issue for Location.", "creator": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "subtasks": [], "reporter": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "environment": "Appcelerator Command-Line Interface, version 5.5.1\r\nOperating System\r\n Name = Mac OS X\r\n Version = 10.11.6\r\nNode.js\r\n Node.js Version = 4.5.0\r\n npm Version = 2.15.9\r\nTitanium CLI\r\n CLI Version = 5.0.9\r\nTitanium SDK\r\n SDK Version = 5.5.1.GA\r\n Target Platform = iphone 5s v10.0.1\r\nXcode: 8\r\n\r\n", "comment": { "comments": [ { "id": "397834", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "*app.js*:\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: '#fff'\r\n});\r\n\r\n// Create a Button.\r\nvar bgService = Ti.UI.createButton({\r\n title: 'StartService'\r\n});\r\n\r\n// The event-listener needs to be outside the background-service\r\nTi.Geolocation.addEventListener('location', function(e) {\r\n if (e.error) {\r\n alert('Error: ' + e.error);\r\n } else {\r\n Ti.API.info(\"value=\" + JSON.stringify(e.coords));\r\n }\r\n});\r\n\r\nfunction bgServiceStart() {\r\n Ti.Geolocation.allowsBackgroundLocationUpdates = true;\r\n Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;\r\n Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;\r\n\r\n Ti.API.info('Registering background services');\r\n var service = Ti.App.iOS.registerBackgroundService({\r\n url: 'bgservice.js'\r\n });\r\n Ti.API.info('*** Press home button to pause application ***');\r\n}\r\n\r\n// Listen for click events.\r\nbgService.addEventListener('click', function() {\r\n // If you havr the AUTHORIZATION_ALWAYS permissions, the blue bar will not be shown\r\n if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE)) {\r\n Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(e) {\r\n if (!e.success) {\r\n Ti.API.error(\"Location permissions not granted: \" + e.error);\r\n return;\r\n }\r\n\r\n bgServiceStart();\r\n });\r\n } else {\r\n bgServiceStart();\r\n }\r\n});\r\n\r\nwin.add(bgService);\r\nwin.open();\r\n{code}\r\n\r\n*bgservice.js*:\r\n{code:javascript}\r\nTi.API.info('bg-service1: service page');\r\n\r\nfunction getCoords() {\r\n Ti.Geolocation.getCurrentPosition(function(e) {\r\n Ti.API.warn(e);\r\n });\r\n}\r\n\r\nsetInterval(function() {\r\n getCoords();\r\n}, 10000);\r\n{code}\r\nIf you have the {{AUTHORIZATION_ALWAYS}} permissions, the bar will not be shown (since the user already agreed to always check the location). So you need the {{AUTHORIZATION_WHEN_IN_USE}} permission and the {{NSLocationWhenInUseUsageDescription}} key only. After that, the bar will be shown when you put your app in the background.\r\n\r\n*EDIT*: And the app just ran 15+ minutes, so the first problem also looks invalid after the made changes. So to note: The (proper) background-service itself it used to stay active > 10 minutes and the permissions are used in conjunction with the background-modes to show the \"blue bar\"\r\n\r\nPlease give it a try. Resolving for now.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-10-01T23:07:42.000+0000", "updated": "2016-10-02T13:05:27.000+0000" }, { "id": "397845", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "In addition, we may place this code (with some more refactoring and documentation) in the [Background Services Guide|docs.appcelerator.com/platform/latest/#!/guide/iOS_Background_Services] and link that to the {{allowsBackgroundLocationUpdates}} docs.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-10-02T13:06:51.000+0000", "updated": "2016-10-02T13:06:51.000+0000" }, { "id": "400457", "author": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "body": "I used your proposed code and the service will killed after 3 minutes. \r\nI start from app.js with `require(\"bgservicestarter\")();`\r\n\r\ncontent of bgservicestarter:\r\nhttps://gist.github.com/AppWerft/a31fdf98132077c37ae33809938c917f\r\n\r\nand here the service: https://gist.github.com/AppWerft/c3dd3b7b2d00da2bd91e034156dcb8d1\r\n\r\nIn tiapp.xml is the UIBackgroundModes key and `NSLocationWhenInUseUsageDescription`\r\n\r\nDon you see way?", "updateAuthor": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-11-05T22:10:59.000+0000", "updated": "2016-11-05T22:10:59.000+0000" }, { "id": "400467", "author": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "body": "Hi Hans,\r\n\r\nI think we need generally AUTHORIZATION_ALWAYS permission? The other is only for foreground - or?\r\nAnd I think \r\nTi.Geolocation.allowsBackgroundLocationUpdates = true;\r\nTi.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_NETWORK;\r\nTi.Geolocation.accuracy = Ti.Geolocation.ACCURACY_THREE_KILOMETERS;\r\nTi.Geolocation.trackSignificantLocationChange = true;\r\nis better then \r\nTi.Geolocation.allowsBackgroundLocationUpdates = true;\r\nTi.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;\r\nTi.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;\r\n\r\nBut I'm not sure. In my app it doesn't work in both cases.\r\nThe app will kill after ca. 200 sec.\r\n\r\nAny ideas why? ", "updateAuthor": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-11-06T18:02:49.000+0000", "updated": "2016-11-06T18:02:49.000+0000" }, { "id": "439912", "author": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Closing as invalid. If incorrect, please reopen.", "updateAuthor": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-08-06T17:37:01.000+0000", "updated": "2018-08-06T17:37:01.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }