• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 如何在 iOS 中的特定时间每天更改 View Controller

[复制链接]
菜鸟教程小白 发表于 2022-12-12 18:17:51 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个案例,用户需要在每天早上 8 点之前提交表单。

当他们提交时,会覆盖一个确认 View 以向用户显示他们已提交并阻止他们再次提交。

早上 8 点之后,我想通过隐藏覆盖 View 来清除表单并让表单 View 再次可用。如果可能,我想在早上 8 点的某个时间点执行此操作。

我正在考虑使用 NSTimer 来完成此任务。我可以设置一个将在早上 8 点运行的计时器来清除表单并移除覆盖 View 吗?

有没有更好的方法来处理这种情况?



Best Answer-推荐答案


您可以使用本地推送通知。官方文档在这里 https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html

类似的东西:

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate date]; // Replace me with your "event" date
localNotification.timeZone = [NSTimeZone localTimeZone];
localNotification.repeatInterval = kCFCalendarUnitDay;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

然后您可以按照文档中的说明“捕捉”通知

If your app is frontmost, the application:didReceiveRemoteNotification: or application:didReceiveLocalNotification:method is called on its app delegate If your app is not frontmost or not running you handle the notifications by checking the options dictionary passed to the application:didFinishLaunchingWithOptions: of your app delegate for either the UIApplicationLaunchOptionsLocalNotificationKey or UIApplicationLaunchOptionsRemoteNotificationKey key.

您不能只使用 NSTimer,因为当您的应用关闭时它不会运行,但是涉及 NSTimer 的另一个解决方案是为事件日期创建一个 NSTimer,然后观察 UIApplicationDidEnterBackgroundNotification ,这里如果定时器正在运行,你将停止定时器,将 timer.fireDate 持久化(你可以将它保存在 NSUserDefault 中),最后观察 UIApplicationDidBecomeActiveNotification,你可以重新创建定时器(减去当前时间与您之前保存的值),或者如果事件时间已经过去,则只触发操作。

关于ios - 如何在 iOS 中的特定时间每天更改 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21414437/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap