【发布时间】:2018-01-02 16:04:55
【问题描述】:
我正在尝试在我的 ios 应用中触发本地通知。
let notificationContent = UNMutableNotificationContent()
notificationContent.title = "Test"
notificationContent.body = alert
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let notificationRequest = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: trigger)
UNUserNotificationCenter.current().add(notificationRequest, withCompletionHandler: { (error) in
if let error = error {
print(error)
}else{
print("local push scheduled!")
}
})
当我尝试运行它时,本地通知已正确安排,但从未触发...一些帮助?
【问题讨论】:
-
您是否请求授权向用户发送通知?
-
是的,我做到了:[.badge, .alert, .sound]
-
好的,设置中说允许通知?
-
是的,我的应用程序启用了课程通知
-
timeInterval 必须为 60 秒或更多秒才能使本地通知生效。