{ "id": "161043", "key": "TIMOB-23506", "fields": { "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "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": "16980", "description": "New V8", "name": "Release 6.0.0", "archived": false, "released": true, "releaseDate": "2016-11-15" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2016-06-13T21:17:15.000+0000", "created": "2016-06-13T16:01:42.000+0000", "priority": { "name": "Critical", "id": "1" }, "labels": [ "applicationWillTerminate", "ios", "titanium" ], "versions": [], "issuelinks": [], "assignee": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2016-10-05T16:42:44.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": "I have an app that has a background service enabled, the user can elect to get a notification that alerts of the app being killed so that the user can manually restart the app.\r\n\r\nThere are some other apps that have this feature, examples are Mile IQ and Kevo (http://stackoverflow.com/questions/22938387/how-to-detect-if-an-ios-app-is-killed-when-it-is-not-in-forground-ios7).\r\n\r\nWhen the app is about to shutdown iOS seems to call *applicationWillTerminate* and gives about 5 seconds, which is enough time to trigger a local notification.\r\n\r\nLooking at the Titanium SDK code, you are already listening for this event, it would be great if we could surface it as a *Titanium.App.addEventListener('willterminate')* event.", "attachment": [], "flagged": false, "summary": "Add event listener for applicationWillTerminate", "creator": { "name": "ulizama", "key": "ulizama", "displayName": "Uriel Lizama", "active": true, "timeZone": "America/Mexico_City" }, "subtasks": [], "reporter": { "name": "ulizama", "key": "ulizama", "displayName": "Uriel Lizama", "active": true, "timeZone": "America/Mexico_City" }, "environment": "iOS", "comment": { "comments": [ { "id": "388225", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "Hey there,\r\n\r\nI had a quick look into our existing code-base and there is an (undocumented) event {{close}} which can be accessed like this:\r\n\r\n{code:javascript}\r\nTi.App.addEventListener(\"close\", function() {\r\n // Application will terminate\r\n});\r\n{code}\r\n\r\nSo different to the {{close}} event in {{Ti.UI.Window}}, this one gets triggered by the core when reaching the {{- (void)applicationWillTerminate:(UIApplication *)application}} delegate. Give it a try! I will add the docs if it works for you. Thanks!", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-06-13T20:07:41.000+0000", "updated": "2016-06-13T20:07:41.000+0000" }, { "id": "388229", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "PR: https://github.com/appcelerator/titanium_mobile/pull/8056\r\nDemo: Paste the below code and quit the app using multitasking. The below log {{applicationWillTerminate}} should be shown in the console.\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor : \"#fff\"\r\n}); \r\n\r\nTi.App.addEventListener(\"close\", function() {\r\n Ti.API.warn(\"applicationWillTerminate\");\r\n});\r\n\r\nwin.open();\r\n{code}", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-06-13T20:34:56.000+0000", "updated": "2016-06-13T20:34:56.000+0000" }, { "id": "388239", "author": { "name": "ulizama", "key": "ulizama", "displayName": "Uriel Lizama", "active": true, "timeZone": "America/Mexico_City" }, "body": "What SDK version are you using?\r\n\r\nI have:\r\n\r\n\r\n\r\n{noformat}\r\n\tTitanium.App.addEventListener(\"close\", function() {\r\n\t Ti.API.warn(\"applicationWillTerminate\");\r\n\t\tvar notification = Ti.App.iOS.scheduleLocalNotification({\r\n\t\t alertBody: 'You app is terminating',\r\n\t\t date: new Date(new Date().getTime() + 100)\r\n\t\t});\r\n\t});\r\n{noformat}\r\n\r\n\r\n\r\nI open the app, move it to background and then remove it using multitasking, but no warning and no notication.\r\n\r\nI'm on 5.2.2.GA", "updateAuthor": { "name": "ulizama", "key": "ulizama", "displayName": "Uriel Lizama", "active": true, "timeZone": "America/Mexico_City" }, "created": "2016-06-13T22:33:14.000+0000", "updated": "2016-06-13T22:34:35.000+0000" }, { "id": "397442", "author": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "With this environment:\r\n\r\nNPM Version: 2.15.9\r\nNode Version: 4.5.0\r\nMac OS: 10.11.6\r\nAppc CLI: 5.5.0\r\nAppc CLI NPM: 4.2.7\r\nTitanium SDK version: 6.0.0.v20160927062927\r\nAppcelerator Studio, build: 4.7.1.201609100950\r\nXcode 8.0 GM\r\n\r\nI created and installed an app using Han's demo code. I opened it, moved it to the background, and then removed it using multitasking, but there was no warning. This was done on a device (iPhone 6S Plus, iOS 10.0.1). In short, I believe the issue is not resolved.", "updateAuthor": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2016-09-28T00:09:48.000+0000", "updated": "2016-09-30T21:43:24.000+0000" }, { "id": "397819", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "[~amukherjee] Did you use the Console.app to watch the logs? There is an known issue regarding logging (TIMOB-23786) that is currently being investigated. I will retry the PR as well, but to be sure, use the Console.app for device-logs. Thx!\r\n\r\n*EDIT*: Just tried, looks good:\r\n{code}\r\n2016-10-01 11:22:32.172 Titanium[1147:23479] [INFO] The application is being shutdown\r\n2016-10-01 11:22:32.173 Titanium[1147:23479] [WARN] applicationWillTerminate\r\n{code}", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-10-01T08:55:19.000+0000", "updated": "2016-10-01T09:23:31.000+0000" }, { "id": "397825", "author": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I had checked the Console Window in Studio. But I will check Console.app and report back.\r\n\r\nUpdate: I tried using iOS SImulator, and did see the warning. I don't have an actual device here; so I'll try that on Monday.", "updateAuthor": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2016-10-01T14:18:55.000+0000", "updated": "2016-10-01T14:36:37.000+0000" }, { "id": "398136", "author": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Using this environment:\r\nNPM Version: 2.15.9\r\nNode Version: 4.5.0\r\nMac OS: 10.11.6\r\nAppc CLI: 5.5.0\r\nAppc CLI NPM: 4.2.7\r\nTitanium SDK version: 5.5.0.GA\r\nAppcelerator Studio, build: 4.8.0.201609290836\r\nXcode 8.0 GM\r\n\r\nI was able to verify that the warning was shown in the console with iOS simulator. Also, with a device, a warning message was shown on the console with an iOS 9.2 phone. There was no warning when using a iOS 10.0 phone.", "updateAuthor": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2016-10-05T16:09:10.000+0000", "updated": "2016-10-05T16:09:10.000+0000" }, { "id": "398137", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "That's only because of TIMOB-23786.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-10-05T16:11:21.000+0000", "updated": "2016-10-05T16:11:21.000+0000" }, { "id": "398142", "author": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Ok, since we have a ticket for iOS 10 device, I'll close this one.", "updateAuthor": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2016-10-05T16:42:34.000+0000", "updated": "2016-10-05T16:42:34.000+0000" } ], "maxResults": 9, "total": 9, "startAt": 0 } } }