Notificações push

Visão Geral

The following guide covers the configuration of the iOS SDK for processing incoming push notifications and sending extracted attribution data to AppsFlyer.

Existem 2 métodos para implementar a integração:

  • By utilizing OneLink in the push payload (recommended method). Step 3 is required only if implementing this solution.
  • Utilizando o JSON simples no payload push (método legado).

Escolha o método certo para você com base na forma como o profissional de marketing estrutura a notificação push.

Integrando a AppsFlyer com notificações push do iOS

A integração da AppsFlyer com as notificações push do iOS consiste no seguinte:

  • Configuração do SDK da AppsFlyer.
  • Configuring a UNUserNotificationCenter delegate.

Prerequisites

Antes de continuar, certifique-se de ter:

  1. Um aplicativo iOS com notificações push habilitadas.
  2. Integrated the SDK.
  3. Se estiver implementando a solução recomendada baseada no OneLink, você precisa do nome da chave dentro do payload de notificação push que contém o OneLink (fornecido pelo profissional de marketing do aplicativo).

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. Implemente o representante de UNUserNotificationCenter delegate. In the didReceive , chame 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:

    • A chave necessária existe no payload.
    • A chave contém uma URL do OneLink válida.

📘

Observação

addPushNotificationDeepLinkPath accepts an array of strings too, to allow you to extract the relevant key from nested JSON structures. For more information, see addPushNotificationDeepLinkPath.