For my iOS
application, what event will be triggered when user a is about to delete the application?

- 5,753
- 72
- 57
- 129

- 495
- 1
- 4
- 9
3 Answers
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.

- 15,096
- 4
- 70
- 83

- 3,925
- 1
- 32
- 43
-
The user can't delete the app when its running, the notification won't fire because the App is either already terminated or freezed in memory. – JustSid Aug 02 '11 at 12:10
-
Yes that's what I'm saying ;) Every time the app is terminated, pray your user don't delete the app after that, you have no way to know. – Remy Vanherweghem Aug 02 '11 at 14:45
-
Ah, I see. Sorry, I misunderstood that. – JustSid Aug 02 '11 at 15:43
-
1I'm storing some data into the keychain and would like the delete it when the user remove the application. – Water7 Aug 04 '11 at 08:05
-
1You could use push-notifications feedback service http://stackoverflow.com/questions/7911976/delegate-method-when-deleting-app – Luis Ascorbe Feb 18 '13 at 15:12
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.
- Make sure you store all your user Data by using combination of user id and device identifier as primary key.
- Consider a bool value for each device identifier for each user.
- When user logins to the app, make a service call and set bool to true for that device identifier and user id on server.
- When user logouts of the app, make a service call and set bool to false for that device identifier and user id. Delete all the user specific data( from device and backend) while logging out(Depends on your business logic).
- Now, if the user logins again and uninstalls the app without logging out, the bool will be left true and all the corresponding user and device specific data will not be deleted.
- When user logins on a device, check for that bool value before updating it to true. If it is already true, it means that the same user has uninstalled this app on that particular device and installed it again on the same device.
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.

- 55
- 1
- 6
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.

- 51,577
- 12
- 107
- 152