Intégrer le SDK
Découvrez comment télécharger et installer le SDK iOS.
Avant de commencer
- Avant de procéder à l'intégration, vous devez installer le SDK.
- Ce document contient des exemples de mise en œuvre. Veillez à remplacer les éléments suivants :
<YOUR_DEV_KEY>
: la clé dev AppsFlyer.<APPLE_APP_ID>
: l'identifiant de l'app Apple (sans leid
préfixe).- Balises supplémentaires, le cas échéant.
Initialisation du SDK iOS
Étape 1 : Importer les dépendances
Importer AppsFlyerLib
:
// AppDelegate.h
#import <AppsFlyerLib/AppsFlyerLib.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end
import UIKit
import AppsFlyerLib
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
}
Étape 2 : initialiser le SDK
In didFinishLaunchingWithOptions
configurez votre ID Apple App et la clé dev AppsFlyer :
[[AppsFlyerLib shared] setAppsFlyerDevKey:@"<YOUR_DEV_KEY>"];
[[AppsFlyerLib shared] setAppleAppID:@"<APPLE_APP_ID>"];
AppsFlyerLib.shared().appsFlyerDevKey = "<YOUR_DEV_KEY>"
AppsFlyerLib.shared().appleAppID = "<APPLE_APP_ID>"
Démarrage du SDK iOS
In applicationDidBecomeActive
, call start
:
[[AppsFlyerLib shared] start];
func applicationDidBecomeActive(_ application: UIApplication) {
AppsFlyerLib.shared().start()
// ...
}
Add SceneDelegate support
OPTIONNELLE
La procédure ci-dessous ne s'applique que si vous utilisez SceneDelegate
s :
In didFinishLaunchingWithOptions
, ajoutez UIApplicationDidBecomeActiveNotification
et configurez-le pour qu'il fonctionne start
:
@implementation AppDelegate
// SceneDelegate support - start AppsFlyer SDK
- (void)sendLaunch:(UIApplication *)application {
[[AppsFlyerLib shared] start];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
// SceneDelegate support
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sendLaunch:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
// ...
return YES;
}
// ...
@end
import UIKit
import AppsFlyerLib
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
// SceneDelegate support
NotificationCenter.default.addObserver(self, selector: NSSelectorFromString("sendLaunch"), name: UIApplicationdidBecomeActiveNotification, object: nil)
return true
}
// SceneDelegate support - start AppsFlyer SDK
@objc func sendLaunch() {
AppsFlyerLib.shared().start()
}
// ...
}
Start with completion handler
OPTIONNELLE
Pour avoir la confirmation que le SDK a bien démarré et que l'information a été transmiseaux serveurs AppsFlyer, appelez start
avec un gestionnaire d'achèvement. Vous pouvez ensuite utiliser cette méthode pour suivre le succès ou l'échec des lancements du SDK.
[[AppsFlyerLib shared] startWithCompletionHandler:^(NSDictionary<NSString *,id> *dictionary, NSError *error) {
if (error) {
NSLog(@"%@", error);
return;
}
if (dictionary) {
NSLog(@"%@", dictionary);
return;
}
}];
AppsFlyerLib.shared()?.start(completionHandler: { (dictionary, error) in
if (error != nil){
print(error ?? "")
return
} else {
print(dictionary ?? "")
return
}
})
Exemple complet
#import "AppDelegate.h"
#import <AppsFlyerLib/AppsFlyerLib.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
// Start the AppsFlyer SDK
- (void)sendLaunch:(UIApplication *)application {
[[AppsFlyerLib shared] start];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
/** APPSFLYER INIT **/
[AppsFlyerLib shared].appsFlyerDevKey = @"<YOUR_DEV_KEY>";
[AppsFlyerLib shared].appleAppID = @"<APPLE_APP_ID>";
/* Uncomment the following line to see AppsFlyer debug logs */
// [AppsFlyerLib shared].isDebug = true;
// SceneDelegate support
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sendLaunch:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
if (@available(iOS 10, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
}];
}
else {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
[[UIApplication sharedApplication] registerForRemoteNotifications];
return YES;
}
@end
import UIKit
import AppsFlyerLib
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AppsFlyerLib.shared().appsFlyerDevKey = "<YOUR_DEV_KEY>"
AppsFlyerLib.shared().appleAppID = "<APPLE_APP_ID>"
/* Uncomment the following line to see AppsFlyer debug logs */
// AppsFlyerLib.shared().isDebug = true
// SceneDelegate support
NotificationCenter.default.addObserver(self, selector: NSSelectorFromString("sendLaunch"), name: UIApplication.didBecomeActiveNotification, object: nil)
return true
}
// SceneDelegate support
@objc func sendLaunch() {
AppsFlyerLib.shared().start()
}
// ...
}
Setting the Customer User ID
OPTIONNELLE
The Customer User ID (CUID) is a unique user identifier created outside the SDK by the app owner. If made available to the SDK, it can be associated with installs and other in-app events. These CUID-tagged events can be cross-referenced with user data from other devices and applications.
Set the CUID
To set the CUID:
[AppsFlyerLib shared].customerUserID = @"my user id";
AppsFlyerLib.shared().customerUserID = "my user id"
Set the CUID before calling start
It is preferable to set the customerUserId
before calling the start
method. This is because start
sends the install event to AppsFlyer. If the CUID is set after calling start
, it will not be associated with the install event.
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Your custom logic of retrieving CUID
NSString *customUserId = [[NSUserDefaults standardUserDefaults] stringForKey:@"customerUserId"];
if (customUserId != nil && ![customUserId isEqual: @""]) {
// Set CUID in AppsFlyer SDK for this session
[AppsFlyerLib shared].customerUserID = customUserId;
// Start
[[AppsFlyerLib shared] start];
}
}
func applicationDidBecomeActive(_ application: UIApplication) {
// your logic to retrieve CUID
let customUserId = UserDefaults.standard.string(forKey: "customUserId")
if(customUserId != nil && customUserId != ""){
// Set CUID in AppsFlyer SDK for this session
AppsFlyerLib.shared().customerUserID = customUserId
AppsFlyerLib.shared().start() // Start
}
}
Prise en charge iOS 14
Vous trouverez ci-dessous des guides sur la configuration de la prise en charge des fonctionnalités iOS 14 et +.
Enabling App Tracking Transparency (ATT) support
Depuis iOS 14.5, l'accès à l'IDFA est régi par l'infrastructure ATT.
En activant le support ATT dans le SDK vous pouvez gérer la collecte des IDFA sur les appareils sous iOS 14.5
et +.
Attention
Appelez
waitForATTUserAuthorization
uniquement si vous prévoyez d'appelerrequestTrackingAuthorization
à un endroit de votre application.
Étape 1 : Configuration waitForATTUserAuthorization
Lors de l'initialisation du SDK, avant d'appelerstart
In didFinishLaunchingWithOptions
, call waitForATTUserAuthorization
:
[[AppsFlyerLib shared] waitForATTUserAuthorizationWithTimeoutInterval:60];
AppsFlyerLib.shared().waitForATTUserAuthorization(timeoutInterval: 60)
Définis timeoutInterval
de manière à ce que vos utilisateurs aient suffisamment de temps pour voir la boîte de dialogue de consentement ATT et y répondre. Voici quelques exemples :
- Si la boîte de dialogue de consentement ATT s'affiche au lancement de l'app, un intervalle de 60 secondes devrait suffire
- Si la boîte de dialogue de consentement ATT s'ouvre après un tutoriel d'environ 2 minutes, un intervalle de 120 secondes suffit.
Étape 2 : Appel requestTrackingAuthorization
Appelez requestTrackingAuthorization
où vous souhaitez afficher le message :
- (void)didBecomeActiveNotification {
// start is usually called here:
// [[AppsFlyerLib shared] start];
if @available(iOS 14, *) {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
NSLog(@"Status: %lu", (unsigned long)status);
}];
}
}
@objc func didBecomeActiveNotification() {
// start is usually called here:
// AppsFlyerLib.shared().start()
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { (status) in
switch status {
case .denied:
print("AuthorizationSatus is denied")
case .notDetermined:
print("AuthorizationSatus is notDetermined")
case .restricted:
print("AuthorizationSatus is restricted")
case .authorized:
print("AuthorizationSatus is authorized")
@unknown default:
fatalError("Invalid authorization status")
}
}
}
}
Remarque
- Vous devez importer l'infrastructure
AppTrackingTransparency
pour pouvoir appelerrequestTrackingAuthorization
.- D'après les instructions d'Apple :
requestTrackingAuthorization
est invoqué uniquement si l'application a le statutUIApplicationStateActive
.requestTrackingAuthorization
ne peut pas être invoqué depuis les extensions d'app.
Customizing the ATT consent dialog
La boîte de dialogue de consentement ATT peut être personnalisée en modifiant dans votre projet Xcode info.plist
:
Pour des instructions détaillées, voir la documentation d'Apple.
Attributing App Clips
L'attribution des clips d'app Apple est disponible à partir du SDK IOS V6.0.8
Consultez notre guide d'intégration des clips d'app pour avoir les instructions détaillées.
Sending SKAN postback copies to AppsFlyer
iOS 15
Configurez votre app pour envoyer des copies de postback à AppsFlyer.
Pour enregistrer le point de terminaison AppsFlyer :
- Ajoutez
NSAdvertisingAttributionReportEndpoint
comme clé auinfo.plist
. - Définissez la valeur de la clé sur
https://appsflyer-skadnetwork.com/
.
Selon Apple, vous ne pouvez définir qu'un seul point de terminaison. La copie des postbacks reçus est disponible dans le rapport des copies de postbacks.
Activation du mode débogage
Vous pouvez activer les journaux de débogage en réglant isDebug sur true
:
[AppsFlyerLib shared].isDebug = true;
AppsFlyerLib.shared().isDebug = true
Remarque
Pour que les journaux de débogage soient complets, veuillez définir
isDebug
avant d'invoquer d'autres méthodes du SDK.Voir l'exemple.
Avertissement
Pour éviter la fuite d'informations sensibles, assurez-vous que les journaux de débogage sont désactivés avant de distribuer l'app.
Test de l'intégration
Pour obtenir des instructions détaillées sur les tests d'intégration, vous pouvez consulter notre guide du test de l'intégration SDK IOS.
Mis(e) à jour il y a 17 jours