ios - Swift 处理日期更改事件

标签 ios xcode swift date

如何在 swift 中处理日期更改事件?

我想在日期更改时创建一组通知。

 var localNotification: UILocalNotification = UILocalNotification()
    localNotification.alertAction = "Testing notifications on iOS8"
    localNotification.alertBody = " Woww it works!!"
    localNotification.fireDate = date
    UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

最佳答案

可以订阅UIApplicationSignificantTimeChangeNotification .这个应该在日期改变时触发。

不幸的是,这个也会在其他场合触发。因此,您应该存储一个静态变量,其中包含此通知最后一次触发的日期,然后检查它是否确实更改了

我不知道您要用它做什么,但在大多数情况下,一般重要的时间变化正是人们所寻找的。

关于ios - Swift 处理日期更改事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31116861/

相关文章:

iphone - 无法在 View 中使用自动布局 "on"移动 UILabel 的 Y 位置

ios - 如何使用后缀中的 CFBundleShortVersionString 动态获取 "Archive Name"(在编辑方案/存档/存档名称中)?

swift - 如何将 "Text(example1: "ex 1", example2: "ex 2")"转换为可用的字典

iphone - iOS 5 中的单元测试 : Is there a way to remove STAssertTrue() lines from the editor temporarily?

ios - 修改常量值

ios - 导航返回按钮方法

swift - Xcode升级后Core Data出现数据丢失

swift - 在不使用 NSUserDefaults 的情况下在本地存储信息

objective-c - 在 Objective-C 中使用 Swift 扩展方法

swift - 在 swift 中实现手势识别器后,如何找到按钮标签?