UILocalNotification Not Firing iOS 8.4


Printing description of localNotification:

{火灾日期=星期三,2015年8月5日上午9:00:00印度标准时间,时区= (null),重复间隔= NSCalendarUnitDay,重复计数= UILocalNotificationInfiniteRepeatCount,下一个fire日期=星期四,2015年8月6日印度标准时间9:00:00 AM,用户信息= (null)}

正如你所看到的时间是上午9:00:00,但它从来没有触发这里我在做什么

  • 我正在测试模拟器通过改变我的Mac时间,是这种情况吗?
  • 我也试着把我的mac时间更改为下一个fire日期,但仍然不起作用。
  • 这些会在Live设备中完美工作吗?
<标题> 更新代码
 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)

这是因为您没有将timezone设置为系统时区。默认情况下,它根据您的位置而不是根据系统时间设置时区。试着把这个添加到你的代码中:

    notification.timeZone = NSTimeZone.systemTimeZone()

这将把您的通知时区更改为系统时区,然后如果您更改了时间,通知将启动。

希望这对你有帮助

最新更新