Ios 试图启动UILocalNotification时不起作用
我正在使用下面的代码创建一个通知,但不知怎么的,它没有启动。我真的只想在打开某个视图控制器时触发它,但到目前为止还没有触发任何东西。我的代码有什么问题Ios 试图启动UILocalNotification时不起作用,ios,swift,swift3,uilocalnotification,Ios,Swift,Swift3,Uilocalnotification,我正在使用下面的代码创建一个通知,但不知怎么的,它没有启动。我真的只想在打开某个视图控制器时触发它,但到目前为止还没有触发任何东西。我的代码有什么问题 func notify() { let notification = UILocalNotification() notification.fireDate = Date() notification.repeatInterval = .minute notification.alertBody = "The al
func notify() {
let notification = UILocalNotification()
notification.fireDate = Date()
notification.repeatInterval = .minute
notification.alertBody = "The alert body"
notification.alertAction = "enter text here"
UIApplication.shared.scheduleLocalNotification(notification)
}
我在app delegate中还有一行:
application.registerUserNotificationSettings(UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil))
我认为这会失败的一个原因是
notification.fireDate=Date()
会将fireDate
设置为当前时间,当管理UserNotifications的(单独的)进程收到您要触发通知的警报时,该时间将在过去。考虑移动到<代码> un通知<代码> S/< P> < P>我将射击日期更改为未来某个时间(晚上6点是我使用日历组件将其更改为06:03,然后它似乎起作用了。通知被触发:)/P>这就是它!当我将日期更改为稍晚一点时,它再次工作并向我发出通知。