SDK 연동

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

시작하기 전에

  • 연동하기 전에 SDK를 설치해야 합니다.
  • 아래 문서는 구현 예시를 보여줍니다. 다음을 꼭 대체해야 합니다.
    • <YOUR_DEV_KEY>: 앱스플라이어 dev key.
    • <APPLE_APP_ID>를 사용하여 직접 검색할 수 있습니다: 애플 앱 ID(접두사 id 제외).
    • 필요에 따른 추가 자리 표시자.

iOS SDK 초기화하기

1단계: 의존성 가져오기
가져오기 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 Apple 앱 ID 및 앱스플라이어 dev key를 구성합니다.

[[AppsFlyerLib shared] setAppsFlyerDevKey:@"<YOUR_DEV_KEY>"];
[[AppsFlyerLib shared] setAppleAppID:@"<APPLE_APP_ID>"];
AppsFlyerLib.shared().appsFlyerDevKey = "<YOUR_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

선택 가능
사용자가 SceneDelegate를 사용하는 경우에만 다음을 수행하십시오.

In didFinishLaunchingWithOptions, UIApplicationDidBecomeActiveNotification 옵저버를 추가하고 실행되도록 설정합니다 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

선택 가능
SDK가 성공적으로 시작되고 앱스플라이어 서버에 통보되었는지 확인하려면 완료 핸들러를 사용하여 start 에 문의하십시오. 이 논리를 적용하여 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
            }
        })

전체 예제

#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()
    }
// ...
}

Github 링크

고객 사용자 ID 설정

선택 가능
CUID(고객 사용자 ID)는 앱 소유자가 SDK 외부에서 만든 고유한 사용자 식별자입니다. SDK에서 사용할 수 있도록 설정한 경우 인스톨 및 기타 인앱이벤트와 연결할 수 있습니다. 이러한 CUID 태그 지정 이벤트는 다른 디바이스 및 애플리케이션의 사용자 데이터와 상호 참조할 수 있습니다.

Set the CUID

CUID를 설정하려면:

[AppsFlyerLib shared].customerUserID = @"my user id";
AppsFlyerLib.shared().customerUserID = "my user id"

Set the CUID before calling start

여기서 customerUserIdstart 메서드를 호출하기 전에 설정하는 것이 좋습니다 이것은 start 이 인스톨 이벤트를 앱스플라이어에 보내기 때문입니다. CUID가 start를 호출한 후에 설정되면, 인스톨 이벤트와 연결되지 않습니다.

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

iOS 14 지원

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

Enabling App Tracking Transparency (ATT) support

iOS 14.5부터 IDFA에 대한 접근은 ATT 프레임워크가 통제합니다.
SDK에서 ATT 지원을 사용하면 iOS 14.5이상이 설치된 기기에서 IDFA 모음을 처리할 수 있습니다.

🚧

주의사항

통화 waitForATTUserAuthorization 앱의 어딘가에서 requestTrackingAuthorization 에 전화를 걸 생각이 있는 경우에만 입니다.

1단계: 설정하기 waitForATTUserAuthorization
SDK를 초기화할 때, start In didFinishLaunchingWithOptions, call waitForATTUserAuthorization:

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

Github 링크

설정 timeoutInterval 을 호출하기 전에 사용자에게 ATT 대화상자 내용을 충분히 읽어보고 선택할 시간을 가질 수 있도록 합니다. 몇 가지 예시:

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

2단계: 호출하기 requestTrackingAuthorization
통화 requestTrackingAuthorization 프롬프트를 표시할 곳에:

- (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 링크

📘

참고

  • 사용자는 AppTrackingTransparency 프레임워크를 가져와 requestTrackingAuthorization.
  • Apple 문서에 따르면:
    • requestTrackingAuthorization 를 호출해야 합니다. 앱이 다음 상태에 있을 때만 호출됩니다 UIApplicationStateActive .
    • requestTrackingAuthorization App Extensions에서 호출 할 수 없습니다.

Customizing the ATT consent dialog

Xcode 프로젝트의 다음을 수정하여 ATT 승인 대화상자를 사용자정의할 수 있습니다. info.plist:

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

Attributing App Clips

Apple App Clip 어트리뷰션은 다음 iOS SDK V6.0.8부터 지원됩니다. 자세한 안내는 App Clip 연동 가이드를 참조하세요.

Sending SKAN postback copies to AppsFlyer

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

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

  1. 다음을 NSAdvertisingAttributionReportEndpoint 앱의 키 info.plist.
  2. 키 값을 다음을 설정합니다: https://appsflyer-skadnetwork.com/.

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

디버그 모드 활성화하기

isDebug를 다음 값으로 설정하여 디버그 로그를 활성화할 수 있습니다: true:

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

📘

참고

전체 디버그 로그를 보려면 다른 SDK 메서드를 호출하기 전에 isDebug 를 설정해야 합니다.

를 참조하십시오.

🚧

경고

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

연동 테스트하기

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