gpt4 book ai didi

swift - UILocalNotification 不触发 iOS 8.4

转载 作者:搜寻专家 更新时间:2023-11-01 05:40:04 25 4
gpt4 key购买 nike

Printing description of localNotification:

{fire date = Wednesday, August 5, 2015 at 9:00:00 AM India Standard Time, time zone = (null), repeat interval = NSCalendarUnitDay, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Thursday, August 6, 2015 at 9:00:00 AM India Standard Time, user info = (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)

最佳答案

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

    notification.timeZone = NSTimeZone.systemTimeZone()

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

希望这有帮助:)

关于swift - UILocalNotification 不触发 iOS 8.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31794842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com