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:

  1. Una aplicación de iOS con las notificaciones push habilitadas.
  2. Integrated the SDK.
  3. 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

  1. 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()
    }
    
  2. Implementa el delegado UNUserNotificationCenter delegate. In the didReceive , llama a handlePushNotification:

    @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]])
      }
    }
    
  3. This step is required only if you're implementing the recommended OneLink-based solution.
    In didFinishLaunchingWithOptions, call addPushNotificationDeepLinkPath before calling start:

    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 calling addPushNotificationDeepLinkPath 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, see addPushNotificationDeepLinkPath.