【问题标题】:UILocalNotification Not Firing iOS 8.4UILocalNotification 未触发 iOS 8.4
【发布时间】:2015-08-03 19:02:43
【问题描述】:
Printing description of localNotification:

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

如您所见,时间是上午 9:00:00,但它永远不会在这里触发我正在做的事情

  • 我正在通过更改我的 Mac 时间在模拟器上进行测试,是这样吗?
  • 我也厌倦了将我的 mac 时间更改为下一个开火日期,仍然无法正常工作。
  • 这些可以在 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)

【问题讨论】:

    标签: swift timezone uilocalnotification ios8.4


    【解决方案1】:

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

        notification.timeZone = NSTimeZone.systemTimeZone()
    

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

    希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      相关资源
      最近更新 更多