在iOS10上,userNotification没有在Banners中显示没有错误,只有在iPhone被锁定时才有效

时间:2018-02-17 15:55:32

标签: ios swift notifications

我设置3秒钟通知我这条消息,但我等了30秒甚至没有任何事情发生在横幅上。但是,如果我锁定iPhone,则会在锁定屏幕上按时显示一条消息。我试了几次,他们都得到了这个结果。我困惑了3天,希望有人帮我解决这个问题。非常感谢您的建议!
这是与userNotifications相关的所有代码

let content = UNMutableNotificationContent()
    content.title = "Tomorrow night"
    content.subtitle = "Old place"
    content.body = "A meal"
    content.badge = 1

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3, repeats: false)
    //let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)

    let requestIdentifier = "com.cheio.Stundenplan"

    let request = UNNotificationRequest(identifier: requestIdentifier,
                                        content: content, trigger: trigger)

    UNUserNotificationCenter.current().add(request) { error in
        if error == nil {
            print("Time Interval Notification scheduled: \(requestIdentifier)")
        }
    }

1 个答案:

答案 0 :(得分:0)

当应用运行时,默认情况下不会显示通知。

如果您仍想提交通知,请在通知中心的willPresent通知方法中调用完成处理程序。

请注意,通知通常用于打开应用。考虑直接在正在运行的应用中显示来自通知的信息。