简体   繁体   中英

Is there a way to keep track of elapsed time even after app is “Deleted”?

I am developing an app (iPAD only) which shows user a pop up box after every 3 days (business requirement) from the "First" time he has installed the app. I am using NSTimer to do it. The implementation breaks if the user deletes the app and reinstalls the app before three days period. In this case the counter for 3 days restarts. I know using Date might not be a good idea because user can change it from settings.

Is there a way I can keep the NSTimer (or anything similar) to keep running even after app is deleted?

NSTimer* msgTimer = [NSTimer scheduledTimerWithTimeInterval: 259200 target: self selector: @selector(showMsg:) userInfo: nil repeats: NO];

The only way I can think of doing this is every time the app is closed save a string representation of the last notification time in the keychain. The keychain is not cleared when the app is removed. Although this is technically a misuse of the keychain it would probably work and I doubt you would have any store submission problems.

Whenever the app is launched check if it is the first time it is launched since last installation (save this information in defaults). If it is the first time, check the keychain timestamp, compare against the current timestamp and go from there.

Say the user deletes the app and installs it the next day. Check keychain and you would see it was deleted 23 hours ago, then start your timer with 23 hours subtracted (so it will notify in 2 days 1 hour). Hope that all makes sense.

Otherwise if the app is generally connected to the internet you could use some sort of server.

No your app is sandboxed anything you do is gone when the app is deleted. You would need the help of some kind of web service to acheive your desired behavior

I don't believe so but I could be wrong (someone can be correct me). Even if it is possible though this sounds like bad way to do something like this.

How about using Local Push Notifications to achieve something like this? Seems ideal for the situation.

Relevant Appl docs for setting up scheduled notifications

You can also use iCloud's key-value data storage to store the initial install date. If you store the date both locally and sync it from iCloud, then it will be difficult for the user to avoid getting the update unless they stay off the Internet.

This, of course, is dependent on them being logged into iCloud on the device and requires iOS 5 or greater.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM