Notifications push
Vue d'ensemble
The following guide covers the configuration of the iOS SDK for processing incoming push notifications and sending extracted attribution data to AppsFlyer.
2 méthodes sont possibles pour implémenter l’intégration :
- By utilizing OneLink in the push payload (recommended method). Step 3 is required only if implementing this solution.
- En utilisant JSON simple dans la charge utile push (méthode héritée).
Choisissez la méthode en fonction de la manière dont le marketeur a structuré la notification push.
Intégrer AppsFlyer aux notifications push iOS
L'intégration d'AppsFlyer aux notifications push iOS se déroule selon les étapes suivantes :
- Configurer le SDK AppsFlyer.
- Configuring a
UNUserNotificationCenter
delegate.
Prerequisites
Avant de commencer, vérifiez que vous disposez des éléments suivants :
- Une app iOS avec les notifications push activées.
- Integrated the SDK.
- Si vous implémentez la solution via OneLink recommandée, vous aurez besoin du nom de la clé située dans la charge utile de la notification push qui contient le OneLink (fournie par le marketeur de l’app).
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() }
-
Implémentez le
UNUserNotificationCenter
delegate. In thedidReceive
comme méthode, appelezhandlePushNotification
:@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 clé requise est présente dans la charge utile.
- La clé contient une URL OneLink valide.
Remarque
addPushNotificationDeepLinkPath
accepts an array of strings too, to allow you to extract the relevant key from nested JSON structures. For more information, seeaddPushNotificationDeepLinkPath
.
Mis(e) à jour il y a 8 mois