Printing description of localNotification:
{fire date = 2015年8月5日星期三上午9:00:00印度标准时间,时区 =(null),repeat interval = NSCalendarUnitDay,repeat count = UILocalNotificationInfiniteRepeatCount,next fire date = Thursday, 2015年8月6日上午9:00:00印度标准时间,用户信息=(null)}
正如你所看到的那样,时间是早上9点00分,但它永远不会在这里发射我正在做的事情
var calendar = NSCalendar.currentCalendar()
// calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
let comp = NSDateComponents()
//comp.timeZone = NSTimeZone(forSecondsFromGMT: 0)
comp.day = NSDate().day()
comp.month = NSDate().month()
comp.year = NSDate().year()
comp.hour = date.hour()
comp.minute = date.minute()
var grouptimestamp = calendar.dateFromComponents(comp)?.getCurrentTimeStemp()
var minutes = self.getMinutestFromTimestemp(NSDate.getCurrentTimeStemp() - grouptimestamp!)
if minutes > 59 {
println("Missed")
}else if minutes < -5 {
println("Early")
}else{
println("Takenow")
}
UIApplication.sharedApplication().cancelAllLocalNotifications()
var localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "Myplan"
localNotification.alertBody = "Woww it works!!"
localNotification.fireDate = NSDate(timeIntervalSince1970: NSTimeInterval(grouptimestamp!))
localNotification.repeatInterval = NSCalendarUnit.CalendarUnitDay
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
答案 0 :(得分:0)
这是因为您尚未将timezone
设置为系统时区。默认情况下,它根据您的位置设置时区,而不是根据系统时间设置。
尝试将其添加到您的代码中:
notification.timeZone = NSTimeZone.systemTimeZone()
这会将您的通知时区更改为系统时区,如果您更改时间,则会启动通知。
希望这会有所帮助:)