我使用此代码在应用程序处于前台时处理远程推送通知:
// 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])
}
但是我仍然无法在应用程序运行时获取它们,我只能在应用程序处于后台模式时获取它们。我想这与我升级到Swift 4.2有关,但是我不确定。应用已发布,我将生产证书用于APN。