Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS本地通知显示在模拟器中,但不显示在设备中_Ios_Swift - Fatal编程技术网

iOS本地通知显示在模拟器中,但不显示在设备中

iOS本地通知显示在模拟器中,但不显示在设备中,ios,swift,Ios,Swift,我有一个Firebase侦听器,当它这样启动时会启动通知: chat.ref.child("lastMessage").observe(.value, with: { snapshot in let lastMessage = snapshot.value as! String chat.lastMessage = lastMessage self.tableView.reloadData() chat.lastMessageText = "New Message

我有一个Firebase侦听器,当它这样启动时会启动通知:

chat.ref.child("lastMessage").observe(.value, with: { snapshot in
    let lastMessage = snapshot.value as! String
    chat.lastMessage = lastMessage
    self.tableView.reloadData()
    chat.lastMessageText = "New Message!"

    let content = UNMutableNotificationContent()
    content.title = "You have a new Message!"
    content.subtitle = chat.title
    content.body = chat.lastMessage
    content.badge = 1

    let trigger = UNTimeIntervalNotificationTrigger (timeInterval: 1, repeats: false)
    let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)

    UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
还有:

override func viewDidLoad() {
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: {didAllow, error in })
}
我遇到的问题是,尽管主屏幕通知在模拟器中工作,但它们没有显示在设备上。在设备上授予所有权限。阅读此处的一些问题,我发现一些答案建议我在应用程序代理中添加以下内容:

application.beginBackgroundTask(withName: "showNotification", expirationHandler: nil)

但这实际上也禁用了模拟器上的通知。这些通知以前确实在设备上起作用,但突然停止。有什么想法吗?

确保在项目设置的“功能”选项卡中启用推送通知。这些是本地通知。