Notificaciones push
Resumen General
The following guide covers the configuration of the iOS SDK for processing incoming push notifications and sending extracted attribution data to AppsFlyer.
Hay 2 métodos para implementar la integración:
- By utilizing OneLink in the push payload (recommended method). Step 3 is required only if implementing this solution.
- Usando JSON simple en la carga útil push (método heredado).
Elige el método adecuado para ti en función de cómo el marketer estructure la notificación push.
Integración de AppsFlyer con las notificaciones push de iOS
La integración de AppsFlyer con las notificaciones push de iOS consiste en lo siguiente:
- Configuración del SDK de AppsFlyer.
- Configuring a
UNUserNotificationCenter
delegate.
Prerequisites
Antes de continuar, asegúrate de tener:
- Una aplicación de iOS con las notificaciones push habilitadas.
- Integrated the SDK.
- Si implementas la solución basada en OneLink recomendada, necesitas el nombre de la clave dentro de la carga útil de la notificación push que contiene el OneLink (proporcionado por el marketer de la aplicación).
Steps
-
Configure the app to use the
UNUserNotificationCenter
delegate:if #available(iOS 10.0, *) { // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter.current().delegate = self let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] UNUserNotificationCenter.current().requestAuthorization( options: authOptions, completionHandler: { _, _ in } ) } else { let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) application.registerUserNotificationSettings(settings) } application.registerForRemoteNotifications() }
-
Implementa el delegado
UNUserNotificationCenter
delegate. In thedidReceive
, llama ahandlePushNotification
:@available(iOS 10, *) extension AppDelegate: UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let userInfo = response.notification.request.content.userInfo print(userInfo) completionHandler() AppsFlyerLib.shared().handlePushNotification(userInfo) } // Receive displayed notifications for iOS 10 devices. func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { let userInfo = notification.request.content.userInfo print(userInfo) // Change this to your preferred presentation option completionHandler([[.alert, .sound]]) } }
-
This step is required only if you're implementing the recommended OneLink-based solution.
IndidFinishLaunchingWithOptions
, calladdPushNotificationDeepLinkPath
before callingstart
:AppsFlyerLib.shared().addPushNotificationDeepLinkPath(["af_push_link"])
In this example, the SDK is configured to look for the
af_push_link
key in the push notification payload.
When callingaddPushNotificationDeepLinkPath
the SDK verifies that:- La clave requerida existe en la carga útil.
- La clave contiene una URL válida de OneLink.
Nota
addPushNotificationDeepLinkPath
accepts an array of strings too, to allow you to extract the relevant key from nested JSON structures. For more information, seeaddPushNotificationDeepLinkPath
.
Actualizado hace 10 meses