Pemberitahuan push
Overview
The following guide covers the configuration of the iOS SDK for processing incoming push notifications and sending extracted attribution data to AppsFlyer.
Ada 2 metode untuk mengimplementasikan integrasi:
- By utilizing OneLink in the push payload (recommended method). Step 3 is required only if implementing this solution.
- Dengan menggunakan JSON biasa di push payload (metode lama).
Pilih metode yang tepat untuk Anda berdasarkan cara pemasar menyusun notifikasi push.
Mengintegrasikan AppsFlyer dengan notifikasi push iOS
Mengintegrasikan AppsFlyer dengan notifikasi push iOS yang terdiri dari:
- Mengonfigurasi SDK AppsFlyer.
- Configuring a
UNUserNotificationCenter
delegate.
Prerequisites
Sebelum melanjutkan, pastikan Anda memiliki:
- Aplikasi iOS dengan notifikasi push diaktifkan.
- Integrated the SDK.
- Jika menerapkan solusi berbasis OneLink yang direkomendasikan, Anda memerlukan nama kode di dalam payload notifikasi push yang berisi OneLink (disediakan oleh pemasar aplikasi).
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() }
-
Terapkan
UNUserNotificationCenter
delegate. In thedidReceive
metode, panggilanhandlePushNotification
:@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:- Kode yang diperlukan ada di payload.
- Kode ini berisi URL OneLink yang valid.
Catatan
addPushNotificationDeepLinkPath
accepts an array of strings too, to allow you to extract the relevant key from nested JSON structures. For more information, seeaddPushNotificationDeepLinkPath
.
Diperbarui 10 bulan yang lalu