在启动一定次数后发出警报
我正在研究这个想法,我希望在应用程序启动一定次数后(假设在 20 次启动后)弹出 UIAlert。
并且会有 2 个按钮。它将重置计数器,使警报在另外 20 次启动后出现。 还有一个按钮可以让它消失并且永远不会再出现。
我该怎么做呢?
I am working on this idea where I want an UIAlert to pop up after a certain amount of launches of the app (let's say after 20 launches).
And there's going to be 2 buttons. One that will reset the counter which will make the alert appear after another 20 launches.
And one button that will make it disappear and never appear again.
How I would do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下 NSUserDefaults 来存储应用程序启动的次数。
Take a look at NSUserDefaults to store a count of the number of times the app has started.
在您的 AppDelegate
applicationDidFinishLaunching:withOptions:
方法中检查NSUserDefaults
:如果用户选择继续显示警报重写计数器,值为 0:
如果用户选择隐藏警报,则将计数器设置为 -1:
In your AppDelegate
applicationDidFinishLaunching:withOptions:
method checkNSUserDefaults
:If user choose continue to show alert rewrite counter with 0:
If user choose to hide alerts set counter to -1:
设置一个柜台。每次应用启动时递增它并将其存储在
NSUserDefaults
中。每次检查是否小于20。如果等于20则重置并重新存储。这有助于获取启动计数
Set up a counter. Increment it each time the app launches and store it in
NSUserDefaults
. Check it each time to make sure it is less than 20. If it is equal to 20 then reset and store again.This helps to get launch count