虽然直到Swift 3我们使用didReceiveRemoteNotification userInfo: [AnyHashable : Any]
方法它的工作正常,但在Swift 4中它不起作用。有没有人对它有任何想法?
答案 0 :(得分:1)
要在应用处于前台时显示通知,请使用以下方法。
// 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])
}
根据apple documentation,您可以在应用运行时显示通知