For my iOS
application, what event will be triggered when user a is about to delete the application?
We cannot exactly know when the user has deleted the application. However, I came across a situation today to detect uninstallation of application which is both device and user specific (only in specific case it will be known).
The following scenario may help you where you need to delete the data based on user and device: If you are using rest API services and authentication for your App, make sure you do this to track it.
Please note that this logic works only if there are service calls in your app and there is some authentication initially. Also, we can know this only if same user tries to login into same device. Uninstallation of application in other use cases can't be known with this logic.
Hoping that this kind of logic may help someone as we are using this logic now. I am a newbie..please guide if I am wrong.
No such thing, sorry.
The best you can do is do is check for the UIApplicationWillTerminateNotification
notification but more importantly save the state of your app (on a server for example) when it's transitioning to the background and cross your fingers your user will not delete your app when it's not running. Because once your app closed, you don't have any control anymore.
EDIT: Since you want to clear the keychain's content when the app is deleted, I suggest you take a look at this other question. Basically, what is suggested by some answers there is not to remove the content of the keychain at delete time, but instead when the user first launches the app using NSUserDefaults.
EDIT: Luis Ascorbe commented with an idea: using Push Notification's feedback service ( https://stackoverflow.com/a/7912045/157401 ) Of course, that's far from perfect (not all users subscribe to the notifications, notification tokens might be invalidated for other reasons, etc.) but that's still something to consider.
EDIT: Starting with iOS 10.3 Beta 2, keychain data appears to no longer be persisted when an app is deleted.
I'm afraid that there is no such notification. When your apps isn't running there's no way it can be notified of changes!
Instead you need to save any state when your user presses the home button, i.e., when it "resigns active." (There's a callback in the UIApplicationDelegate
and you can also listen for notifications.) In general I would not recommend listening for UIApplicationWillTerminateNotification
since it is rarely called on iOS4 where multi-tasking is supported.