Вы можете получить данные уведомлений, используя func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
, но прежде чем вы сможете это сделать, вы должны сделать свой ViewController делегатом UNUserNotificationCenter
при регистрации для уведомлений или в методе didFinishLaunchWithOptions(:)
.
Шаг 1 Сделайте ваш AppDelegate делегатом UNNotificationCenter
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Assumming you have imported NotificationCenter
UNUserNotificationCenter.current().delegate = self
//......
return true
}
Шаг 2 Получите вашу информацию
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print(userInfo) // Your notification info
// Note that you have to cast/parse it depending on which data you want to handle.
}