Detect iOS application about to delete?

前端 未结 3 487
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 09:53

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

相关标签:
3条回答
  • 2020-11-30 10:13

    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.

    1. Make sure you store all your user Data by using combination of user id and device identifier as primary key.
    2. Consider a bool value for each device identifier for each user.
    3. When user logins to the app, make a service call and set bool to true for that device identifier and user id on server.
    4. 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).
    5. 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.
    6. 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.

    0 讨论(0)
  • 2020-11-30 10:25

    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.

    0 讨论(0)
  • 2020-11-30 10:29

    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.

    0 讨论(0)
提交回复
热议问题