尽管在 Swift 3 之前我们使用 didReceiveRemoteNotification userInfo: [AnyHashable : Any]
方法它工作正常,但在 Swift 4 中它不起作用。有人对此有任何想法吗?
最佳答案
要在应用程序处于前台时显示通知,请使用以下方法。
// This method will be called when app received push notifications in foreground
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
completionHandler([.alert, .badge, .sound])
}
据苹果documentation ,您可以在应用程序运行时显示通知
关于ios - 如何在 Swift 4 中应用程序处于运行状态时显示推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47970568/