如何在通知中心显示推送通知

问题描述 投票:4回答:1

所有这些都来自我当前正在开发的一个应用程序,我们将此应用程序称为SampleApp

如何从手机托盘中获得这些通知的列表

enter image description here

是的,我确实知道我可以通过此代码获得通知

if #available(iOS 10.0, *) {           
    UNUserNotificationCenter.current().getPendingNotificationRequests { (requests) in
        print("here are the iOS 10 notifs \(requests)")
    }         
} else {
    let requests = (UIApplication.shared.scheduledLocalNotifications ?? [])
    print("here are the NON iOS 10 notifs \(requests)")
}

但是此代码的问题在于,我只能获取我离线创建]的通知,而不能接收来自Apple Push Notification Server(APNS)的通知”>

我是指离线创建,是预定的UILocalNotification,并且由于Push Notifications不是UILocalNotification,所以我不知道该怎么办

您可能会问的一些问题

  1. 是从我的应用发出的这些通知吗?

    • 我是在didReceiveRemoteNotification上使用AppDelegate吗?

    • 是,但是有所不同。
  2. 我的远程通知是否可以从APNS工作/收到通知

  3. 我的注册远程通知的代码是什么样的?

    if #available(iOS 10.0, *) {
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        let center = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options: authOptions, completionHandler: { (_, _) in })
    } else {
        let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }
    
    application.registerForRemoteNotifications()
    
  4. 所有这些都来自我当前正在开发的一个应用程序,我们将此应用程序称为SampleApp如何从手机托盘中获取这些通知的列表,是的,我确实知道我可以获取...

swift notifications system-tray
1个回答
0
投票

Dávid Pásztor的评论部分解决了该问题,因为现在我可以检索Notification Center

中显示的all
© www.soinside.com 2019 - 2024. All rights reserved.