swift 2 数组中多个日期的本地警报
swift 2 local alert for multiple dates in array
我有一个 nsdates 数组,我想为每个 nsdates 创建一个通知,以便在时间与当前时间匹配时发生。
到目前为止我有这个
for item in stuffThree {
print("test")
var notification:UILocalNotification = UILocalNotification()
notification.category = "test1"
notification.alertBody = "test2"
notification.fireDate = item
print(item)
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
截至目前我没有得到任何东西。我所做的是提前一分钟创建一个日期,然后让时钟滴答滴答地等待,什么也没有发生。
有什么想法吗?
一些建议:
- 设置
notification.alertBody = "Test"
- 致电
localNotification.timeZone = NSTimeZone.defaultTimeZone()
- 使用
print(notification.fireDate)
检查您的输出并
打印(notification
)
- 如果在模拟器中,应用程序打开时可能不会弹出通知,因此请关闭它(shift+cmd+h)
试试这个。
notification.fireDate = NSDate(timeIntervalSinceNow: 5)
您应该在 HackingWithSwift 上阅读 This。它应该能帮到你。
我有一个 nsdates 数组,我想为每个 nsdates 创建一个通知,以便在时间与当前时间匹配时发生。
到目前为止我有这个
for item in stuffThree {
print("test")
var notification:UILocalNotification = UILocalNotification()
notification.category = "test1"
notification.alertBody = "test2"
notification.fireDate = item
print(item)
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
截至目前我没有得到任何东西。我所做的是提前一分钟创建一个日期,然后让时钟滴答滴答地等待,什么也没有发生。
有什么想法吗?
一些建议:
- 设置
notification.alertBody = "Test"
- 致电
localNotification.timeZone = NSTimeZone.defaultTimeZone()
- 使用
print(notification.fireDate)
检查您的输出并 打印(notification
) - 如果在模拟器中,应用程序打开时可能不会弹出通知,因此请关闭它(shift+cmd+h)
试试这个。
notification.fireDate = NSDate(timeIntervalSinceNow: 5)
您应该在 HackingWithSwift 上阅读 This。它应该能帮到你。