시작하기전에
이 문서는 adbrix iOS SDK를 iOS 앱에 통합하는 방법을 다룹니다.
SDK 지원 환경
SDK 설치
adbrix iOS SDK는 CocoaPods, Swift Package Manager(SPM), 수동 설치를 지원합니다.
CocoaPods1. CocoaPods 설치
최신 버전의 CocoaPods을
2. 의존성 추가
Xcode 프로젝트 폴더에 Podfile
추가 후 Podfile에 adbrix SDK 의존성을 추가해주세요
Copy target 'YourAppTarget' do
pod 'adbrix2.0'
end
3. 의존성 설치
터미널에서 다음의 명령어로 SDK를 설치해 주세요
Swift Package Manager(SPM)1. Xcode에서 패키지 의존성 추가
2. adbrix SDK GitHub 저장소 입력
저장소 명은 https://github.com/IGAWorksDev/adbrix-ios-sdk 입니다.
3. Dependency Rule 입력 및 타겟에 adbrix 추가
adbrix SDK는 을 따릅니다.
수동 설치1. 프레임워크 다운로드
에서 최신 프레임워크를 다운로드해 주세요
2. 프로젝트에 프레임워크 추가
Xcode의 Targets -> General -> Frameworks, Libraries, and Embedded Content -> + 클릭 -> Add Others... -> Add Files.. 를 통해 다운로드받은 프레임워크를 추가해 주세요
SDK 초기화
AppDelegate 수정
AppDelegate.Swift 파일에 다음과 같이 SDK를 import 합니다.
AppDelegate 클래스에 sdk초기화 코드를 추가합니다.
Copy @main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Adbrix.shared().sdkInit(appkey: "APP_KEY", secretKey: "SECRET_KEY")
return true
}
}
AppDelegate.m 파일에 다음과 같이 SDK를 import 합니다.
Copy #import <AdbrixSDK/AdbrixSDK.h>
AppDelegate 클래스에 sdk초기화 코드를 추가합니다.
Copy @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[Adbrix shared] sdkInitWithAppkey:@"APP_KEY" secretKey:@"SECRET_KEY"];
return YES;
}
SDK 설정
로그 활성화하기
debug를 위한 로그 활성화 설정입니다. 해당 값 설정 시 로그가 debug conosole에 표시됩니다. (BundleIdentifier).adbrixLogger를 Subsystem으로 합니다.
config
매개변수에 ABConfig.SET_LOG
키와 불리언 값을 설정하여 로그 출력 여부를 제어할 수 있습니다. true
로 설정하면 디버그 콘솔에 로그가 출력되고, false
로 설정하거나 생략하면 로그가 출력되지 않습니다.
예시:
Copy Adbrix.shared().sdkInit(
appkey: "APP_KEY",
secretKey: "SECRET_KEY",
extraConfig: [ABConfig.SET_LOG: true]
)
Copy [[Adbrix shared] sdkInitWithAppkey:@"APP_KEY"
secretKey:@"SECRET_KEY"
extraConfig:@{ABConfig.SET_LOG: @YES}];
딥링크 오픈 분석
앱의 생명주기에 맞춰 다음의 코드를 추가해주세요
AppDelegate
Copy //UniversalLink
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([any UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let deepLinkUrl = userActivity.webpageURL {
Adbrix.shared().deepLinkOpen(url: deepLinkUrl)
}
return true
}
//DeepLink
func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
Adbrix.shared().deepLinkOpen(url: url)
return true
}
Copy // UniversalLink
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb] && userActivity.webpageURL) {
[[Adbrix shared] deepLinkOpenWithUrl:userActivity.webpageURL];
}
return YES;
}
// DeepLink
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
[[Adbrix shared] deepLinkOpenWithUrl:url];
return YES;
}
SceneDelegate
Copy func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// DeepLink
if let deepLinkUrl = connectionOptions.urlContexts.first?.url {
Adbrix.shared().deepLinkOpen(url: deepLinkUrl)
}
// UniversalLink
if let userActivity = connectionOptions.userActivities.first,
userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let deepLinkUrl = userActivity.webpageURL {
Adbrix.shared().deepLinkOpen(url: deepLinkUrl)
}
guard let _ = (scene as? UIWindowScene) else { return }
}
// DeepLink
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let deepLinkUrl = URLContexts.first?.url {
Adbrix.shared().deepLinkOpen(url: deepLinkUrl)
}
}
// UniversalLink
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let deepLinkUrl = userActivity.webpageURL {
Adbrix.shared().deepLinkOpen(url: deepLinkUrl)
}
}
Copy - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// DeepLink
UIOpenURLContext *firstURLContext = connectionOptions.URLContexts.allObjects.firstObject;
if (firstURLContext.URL) {
[[Adbrix shared] deepLinkOpenWithUrl:firstURLContext.URL];
}
// UniversalLink
NSUserActivity *firstActivity = connectionOptions.userActivities.allObjects.firstObject;
if ([firstActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb] && firstActivity.webpageURL) {
[[Adbrix shared] deepLinkOpenWithUrl:firstActivity.webpageURL];
}
}
// DeepLink
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
UIOpenURLContext *firstURLContext = URLContexts.allObjects.firstObject;
if (firstURLContext.URL) {
[[Adbrix shared] deepLinkOpenWithUrl:firstURLContext.URL];
}
}
// UniversalLink
- (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb] && userActivity.webpageURL) {
[[Adbrix shared] deepLinkOpenWithUrl:userActivity.webpageURL];
}
}
SwiftUI
Copy import SwiftUI
import AdbrixSDK
@main
struct SwiftUIApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
Adbrix.shared().deepLinkOpen(url: url)
}
}
}
}
지연된 딥링크(Deferred Deep Link) 핸들링하기
지연된 딥링크는 앱이 설치되지 않은 유저가 링크를 클릭 후 앱을 설치했을때 자동으로 딥링크를 실행합니다. 직접 지연된 딥링크를 핸들링 하려면 다음 메소드를 호출하여 자동 딥링크 실행을 막고 직접 동작 시킬 수 있습니다.
Delegate 설정
AdbrixDeferredDeepLinkDelegate 프로토콜을 채택한 클래스를 Adbrix 인스턴스에 전달후 디퍼드 딥링크가 호출되는 메소드를 구현합니다.
Copy class AppDelegate: UIResponder, UIApplicationDelegate, AdbrixDeferredDeepLinkDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
Adbrix.shared().setDeferredDeepLinkDelegate(self)
return true
}
func didReceive(deferredDeepLink: AdbrixDeepLink) {
if let deepLink = deferredDeepLink.deepLink,
let url = URL(string: deepLink) {
handleDeepLink(url)
}
}
}
Copy @interface AppDelegate () <AdbrixDeferredDeepLinkDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[[Adbrix shared] setDeferredDeepLinkDelegate:self];
return YES;
}
- (void)didReceiveDeferredDeepLink:(AdbrixDeepLink *)deferredDeepLink {
if (deferredDeepLink.deepLink) {
[self handleDeepLink:deferredDeepLink.deepLink];
}
}
@end
위 Delegate 설정을 하지 않으면 서버로부터 전달받은 지연된 딥링크를 SDK에서 자동으로 UIApplication.shared.open(deepLinkUrl)
메소드를 사용하여 호출합니다.
App Tracking Transparency (ATT) 지원
idfa 수집 가능 시점부터 SDK 이벤트를 수집하고 싶다면 SDK 초기화 코드에 다음과 같이 설정 코드를 추가해주세요
ATT 연동
Copy ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .notDetermined:
Adbrix.shared().attAuthorized(false)
case .restricted:
Adbrix.shared().attAuthorized(false)
case .denied:
Adbrix.shared().attAuthorized(false)
case .authorized:
Adbrix.shared().attAuthorized(true)
@unknown default:
Adbrix.shared().attAuthorized(false)
}
}
Copy [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
switch (status) {
case ATTrackingManagerAuthorizationStatusAuthorized:
[[Adbrix shared] attAuthorized:YES];
break;
case ATTrackingManagerAuthorizationStatusDenied:
[[Adbrix shared] attAuthorized:NO];
break;
case ATTrackingManagerAuthorizationStatusRestricted:
[[Adbrix shared] attAuthorized:NO];
break;
case ATTrackingManagerAuthorizationStatusNotDetermined:
[[Adbrix shared] attAuthorized:NO];
break;
default:
[[Adbrix shared] attAuthorized:NO];
break;
}
}];
초기화 코드
SDK 초기화 시 extraConfig
매개변수에 ABConfig.TRACKING_TIMEOUT
설정을 추가하면, 지정된 시간(ABTimeOut)동안 SDK 이벤트를 지연시켜 idfa에 대한 정보를 첫 이벤트 부터 담습니다.
ABTimeOut 설정
ABTimeOut
은 ATT 팝업 응답을 기다리는 최대 시간을 설정하는 열거형입니다. SDK는 이 시간 동안 ATT 팝업에 대한 사용자 응답을 기다린 후 이벤트 수집을 시작합니다.
다음과 같은 옵션이 제공됩니다:
이 설정을 통해 IDFA 수집 가능 여부가 확인된 시점부터 정확한 사용자 데이터를 수집할 수 있습니다.
Copy Adbrix.shared().sdkInit(
appkey: "APP_KEY",
secretKey: "SECRET_KEY",
extraConfig: [
ABConfig.TRACKING_TIMEOUT: ABTimeOut._60
]
)
Copy [[Adbrix shared] sdkInitWithAppkey:@"APP_KEY"
secretKey:@"SECRET_KEY"
extraConfig:@{
ABConfig.TRACKING_TIMEOUT: @(ABTimeOut_60)
}];
완료
SDK 설치 및 초기화가 완료되었습니다.