StageUp
모바일 SDK딥링크

Unity

1. 개요

  • AdStage Unity SDK는 Android/iOS 전반의 딥링크 수신·처리와 생성 기능을 제공합니다.
  • Android(App Links), iOS(Universal Links/URL Schemes)의 플랫폼 사전 설정이 완료되어야 정상 동작합니다.

참고

  • Android: AndroidManifest의 인텐트 필터, 링크 도메인/스킴 설정
  • iOS: Info.plist의 URL Schemes, Associated Domains(AASA) 설정

2. Android 딥링크 수신 설정

AdStage Unity SDK는 기본적으로 NBaseUnityActivity (Assets/Plugins/Android/src/com/nbase/unity/NBaseUnityActivity.java)를 사용합니다. 커스텀 Activity를 사용하는 경우 아래 코드를 추가하세요.

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
    
	nbaseWrapper = new NBaseAndroidWrapper();
	nbaseWrapper.setAdStageApiKey("YOUR_API_KEY");
	nbaseWrapper.setUnifiedListener();
}
 
@Override
protected void onNewIntent(Intent intent) {
	super.onNewIntent(intent);
	setIntent(intent);
    
	if (nbaseWrapper != null) {
		nbaseWrapper.handleDeepLinkIntent(intent);
	}
}

3. iOS 딥링크 수신 설정

기본적으로 UnityAppController (Assets/NBaseSDK/Plugins/iOS/Source/NBaseAppController.mm)를 사용합니다. 커스텀 AppController 사용 시 아래 코드를 추가하세요.

@implementation NBaseUnityAppController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
	[[NBaseUnityPlugin shared] setAdStageApiKey:@"YOUR_API_KEY" :nil];
	[[NBaseUnityPlugin shared] setAdStageUnifiedListener:^(AdStageDeepLink *deepLink) {
		// 딥링크 수신 처리
	}];
    
	return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
	return [[NBaseUnityPlugin shared] handleAdStageDeepLink:url];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler {
	if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
		return [[NBaseUnityPlugin shared] handleAdStageUniversalLink:userActivity];
	}
	return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}

4. Unity 딥링크 수신 처리

Unity 씬에서 이벤트 리스너를 구현해 딥링크를 수신·분기 처리합니다.

using UnityEngine;
using NBaseSDK;
using System.Collections.Generic;
 
public class AdStageListener : MonoBehaviour, NBaseEventListener
{
	void Start()
	{
		DontDestroyOnLoad(this.gameObject);
		NBaseSDK.NBase.SetEventListener(this);
	}
 
	public void OnAdStageDeepLink(NBaseSDK.NBase.AdStageDeepLink deepLink)
	{
		Debug.Log($"Deep link received: {deepLink.Path}");
		Debug.Log($"Event type: {deepLink.EventType}");
 
		foreach (var param in deepLink.Parameters)
		{
			Debug.Log($"Parameter: {param.Key} = {param.Value}");
		}
 
		HandleDeepLink(deepLink);
	}
 
	private void HandleDeepLink(NBaseSDK.NBase.AdStageDeepLink deepLink)
	{
		switch (deepLink.EventType)
		{
			case "OPEN":
				// TODO: 오픈 시 라우팅
				break;
			case "INSTALL":
				// TODO: 설치 후 최초 오픈 라우팅
				break;
		}
	}
}

5. Unity 딥링크 생성 예제

앱 내에서 완전한 딥링크를 생성하고 콜백으로 결과를 수신합니다.

public void CreateCompleteAdStageDeepLink()
{
	var customParameters = new Dictionary<string, object>
	{
		{"level", 10},
		{"stage", "boss_battle"},
		{"reward_type", "gold"},
		{"amount", 1000}
	};
 
	NBaseSDK.NBase.createAdStageDeepLink(
		name: "Special Event Link",
		description: "Boss Battle Event Promotion",
		channel: "facebook",
		campaign: "summer_event_2024",
		adGroup: "boss_battle_ads",
		creative: "boss_banner_v1",
		content: "special_reward",
		keyword: "boss,event,reward",
		parameters: customParameters,
		androidPackageName: "com.yourcompany.yourgame",
		androidAppScheme: "yourgame://",
		androidWebUrl: "https://yourgame.com/android",
		iosAppStoreId: "123456789",
		iosAppScheme: "yourgame://",
		iosWebUrl: "https://yourgame.com/ios",
		webUrl: "https://yourgame.com/web",
		completionHandler: (shortUrl, error) =>
		{
			if (error != null)
			{
				Debug.LogError($"Deep link creation failed: {error.message}");
				return;
			}
			Debug.Log($"Deep link created successfully: {shortUrl}");
		}
	);
}

6. 주의사항

  • setAdStageApiKey() 호출은 앱 시작 시점에 수행하세요.
  • Android/iOS 라이프사이클 콜백 삽입 위치를 정확히 반영하세요.
  • AndroidManifest, Info.plist 내 도메인/스킴 등록 상태를 확인하세요.

목차