这是我在前台应用程序时用于接收推送通知的代码
@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void)
{
completionHandler([UNNotificationPresentationOptions.Alert,UNNotificationPresentationOptions.Sound,UNNotificationPresentationOptions.Badge])
}
但是我的问题是我的通知包含[NSObject:AnyObject]值。如何接收类似背景的通知
最佳答案
将此代码添加到AppDelegate.swift文件中。
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
completionHandler([UNNotificationPresentationOptions.alert,UNNotificationPresentationOptions.sound,UNNotificationPresentationOptions.badge])
}
关于当应用程序在前台时,iOS Swift会收到推送通知,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41340515/