[TIMOB-23506] Add event listener for applicationWillTerminate
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-06-13T21:17:15.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.0.0 |
Components | iOS |
Labels | applicationWillTerminate, ios, titanium |
Reporter | Uriel Lizama |
Assignee | Hans Knöchel |
Created | 2016-06-13T16:01:42.000+0000 |
Updated | 2016-10-05T16:42:44.000+0000 |
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.
There 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).
When 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.
Looking 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.
Hey there, I had a quick look into our existing code-base and there is an (undocumented) event
close
which can be accessed like this:So different to the
close
event inTi.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!PR: https://github.com/appcelerator/titanium_mobile/pull/8056 Demo: Paste the below code and quit the app using multitasking. The below log
applicationWillTerminate
should be shown in the console.What SDK version are you using? I have: {noformat} Titanium.App.addEventListener("close", function() { Ti.API.warn("applicationWillTerminate"); var notification = Ti.App.iOS.scheduleLocalNotification({ alertBody: 'You app is terminating', date: new Date(new Date().getTime() + 100) }); }); {noformat} I open the app, move it to background and then remove it using multitasking, but no warning and no notication. I'm on 5.2.2.GA
With this environment: NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.11.6 Appc CLI: 5.5.0 Appc CLI NPM: 4.2.7 Titanium SDK version: 6.0.0.v20160927062927 Appcelerator Studio, build: 4.7.1.201609100950 Xcode 8.0 GM I 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.
[~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! *EDIT*: Just tried, looks good:
I had checked the Console Window in Studio. But I will check Console.app and report back. Update: 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.
Using this environment: NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.11.6 Appc CLI: 5.5.0 Appc CLI NPM: 4.2.7 Titanium SDK version: 5.5.0.GA Appcelerator Studio, build: 4.8.0.201609290836 Xcode 8.0 GM I 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.
That's only because of TIMOB-23786.
Ok, since we have a ticket for iOS 10 device, I'll close this one.