SDK 연동

iOS SDK를 초기화하고 설치하는 방법을 배웁니다.

시작하기 전에

  • 연동하기 전에 SDK를 설치해야 합니다.
  • 아래 문서는 구현 예시를 보여줍니다. 다음을 꼭 대체해야 합니다.
    • <AF_DEV_KEY>: 앱스플라이어 dev key.
    • <APPLE_APP_ID>: The Apple App ID (without the id prefix).
    • 필요에 따른 추가 자리 표시자.

iOS SDK 초기화하기

1단계: 의존성 가져오기
Import AppsFlyerLib:

// AppDelegate.h
#import <AppsFlyerLib/AppsFlyerLib.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@end
import UIKit
import AppsFlyerLib

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    // ...
}

2단계: SDK 초기화하기
In didFinishLaunchingWithOptions configure your Apple App ID and AppsFlyer dev key:

[[AppsFlyerLib shared] setAppsFlyerDevKey:@"<AF_DEV_KEY>"];
[[AppsFlyerLib shared] setAppleAppID:@"<APPLE_APP_ID>"];
AppsFlyerLib.shared().appsFlyerDevKey = "<AF_DEV_KEY>"
AppsFlyerLib.shared().appleAppID = "<APPLE_APP_ID>"

iOS SDK 시작하기

In applicationDidBecomeActive, call start:

[[AppsFlyerLib shared] start];
func applicationDidBecomeActive(_ application: UIApplication) {
    AppsFlyerLib.shared().start()
    // ...
}

Add SceneDelegate support

선택 가능
Do the following only if you use SceneDelegates:

In didFinishLaunchingWithOptions, add a UIApplicationDidBecomeActiveNotification observer and set it to run 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

선택 가능
To confirm that the SDK started successfully and notified the AppsFlyer servers, call start with a completion handler. You can then apply logic to handle the success or failure of the SDK launch.

[[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
            }
        })

전체 예제

#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 = @"<AF_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, AppsFlyerLibDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        AppsFlyerLib.shared().appsFlyerDevKey = "<AF_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()
    }
// ...
}

Github 링크

iOS 14 지원

다음은 iOS 14이상에 대한 기능 지원 설정에 대한 가이드입니다.

Enabling App Tracking Transparency (ATT) support

Starting iOS 14.5, IDFA access is governed by the ATT framework.
Enabling ATT support in the SDK handles IDFA collection on devices with iOS 14.5+ installed.

🚧

주의사항

Call waitForATTUserAuthorization only if you intend to call requestTrackingAuthorization somewhere in your app.

1단계: 설정하기 waitForATTUserAuthorization
When Initializing the SDK, before calling start In didFinishLaunchingWithOptions, call waitForATTUserAuthorization:

[[AppsFlyerLib shared] waitForATTUserAuthorizationWithTimeoutInterval:60];
AppsFlyerLib.shared().waitForATTUserAuthorization(timeoutInterval: 60)

Github 링크

Set timeoutInterval as such that app users have enough time to see and engage with the ATT prompt. A few examples:

  • ATT 대화상자가 앱을 처음 실행시켰을 때 바로 노출되는 경우, 60초면 충분합니다.
  • ATT 대화상자가 튜토리얼 이후 노출되는 경우, 약 2분, 120초가 적절합니다.

2단계: 호출하기 requestTrackingAuthorization
Call requestTrackingAuthorization where you wish to display the prompt:

- (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")
        }
      }
    }
}

Github 링크

📘

참고

  • You need to import the AppTrackingTransparency framework to call requestTrackingAuthorization.
  • Apple 문서에 따르면:
    • requestTrackingAuthorization is invoked only if the app is in the UIApplicationStateActive state.
    • requestTrackingAuthorization App Extensions에서 호출 할 수 없습니다.

Customizing the ATT consent dialog

The ATT consent dialog can be customized by modifying your Xcode project's info.plist:

더 자세한 내용은 Apple 문서를 참조하세요.

Attributing App Clips

Apple App Clips attribution was introduced in iOS SDK V6.0.8. See our App Clips integration guide for detailed instructions.

Sending SKAN postback copies to AppsFlyer

iOS 15
포스트백 복사본을 앱스플라이어로 보내도록 앱을 설정합니다.

앱스플라이어 엔드포인트 등록 방법:

  1. Add the NSAdvertisingAttributionReportEndpoint key to your app's info.plist.
  2. Set the key's value to https://appsflyer-skadnetwork.com/.

Apple에 따르면 하나의 엔드포인트만 설정할 수 있습니다. 수신된 포스트백의 사본은 포스트백 사본 리포트에서 사용할 수 있습니다.

디버그 모드 활성화하기

You can enable debug logs by setting isDebug to true:

[AppsFlyerLib shared].isDebug = true;
AppsFlyerLib.shared().isDebug = true

📘

참고

To see full debug logs, make sure to set isDebug before invoking other SDK methods.

를 참조하십시오.

🚧

경고

민감한 정보의 누출을 방지하려면 앱을 배포하기 전에 디버그 로그를 비활성화하십시오.

연동 테스트하기

자세한 연동 테스트 지침은 iOS SDK 연동 테스트 가이드를 참조하십시오.


다음 내용