Handling Push Notifications when App is Terminated

后端 未结 7 617
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 03:55

When my App is not running and receives a Push Notification, if I click on that notification, the App is launched - but then it doesn\'t prompt the user with the Alert-View

7条回答
  •  既然无缘
    2020-11-30 04:31

    You can retrieve notifications delivered to your app by using the getDeliveredNotifications(completionHandler:) method. Note that this only returns notifications currently displayed in the Notification Center and not the ones that have been manually cleared by the user.

    UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
    
        // notifications: An array of UNNotification objects representing the local
        // and remote notifications of your app that have been delivered and are still
        // visible in Notification Center. If none of your app’s notifications are
        // visible in Notification Center, the array is empty.
    
        // As said in the documentation, this closure may be executed in a background
        // thread, so if you want to update your UI you'll need to do the following:
        DispatchQueue.main.sync { /* or .async {} */ 
            // update UI
        }
    }
    

提交回复
热议问题