[英]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. 我正在开发一个应用程序(仅适用于iPAD),该应用程序从“首次”安装该应用程序起每隔三天(业务要求)向用户显示一个弹出框。 I am using NSTimer to do it.
我正在使用NSTimer做到这一点。 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(或类似的东西)在删除应用程序后仍保持运行?
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).
检查钥匙串,您会看到它在23小时前被删除,然后以减去23小时的时间启动计时器(因此它将在2天1小时内发出通知)。 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
您将需要某种Web服务的帮助才能实现所需的行为
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 用于设置计划通知的相关Appl文档
You can also use iCloud's key-value data storage to store the initial install date. 您还可以使用iCloud的键值数据存储来存储初始安装日期。 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.
如果您同时在本地存储日期并从iCloud同步日期,那么除非用户不上网,否则用户将很难避免获取更新。
This, of course, is dependent on them being logged into iCloud on the device and requires iOS 5 or greater. 当然,这取决于它们是否已在设备上登录到iCloud,并且需要iOS 5或更高版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.