UILocalNotification仅在锁定屏幕/通知屏幕上显示

时间:2017-12-06 13:57:12

标签: ios swift uilocalnotification

每当应用程序收到静音推送时,我都会显示本地通知。 如果在接收静音推送时,iPhone被锁定,则显示本地通知,但如果应用程序在后台并且iPhone未锁定,则不显示本地通知。可能有什么不对。 ?我使用下面的代码?

    let content = UNMutableNotificationContent()
content.title = "Connect"
content.body = indentificationText
content.sound = UNNotificationSound.default()

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1,
                                                repeats: false)

let appDelegate = UIApplication.shared.delegate as! AppDelegate

UNUserNotificationCenter.current().delegate = appDelegate
content.userInfo = payload.dictionaryPayload


let request = UNNotificationRequest(identifier: content.title, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { (error) in
    NSLog("UNUserNotificationCenter Add completion Handler : \(String(describing: error?.localizedDescription))")
})

1 个答案:

答案 0 :(得分:1)

应用可能会暂停在后台中,因此不会执行创建本地通知的代码。 。

相关问题