Flutter Flutter 애플리케이션에서 NBase AdStage SDK를 사용한 딥링크 구현 가이드입니다.
딥링크는 사용자를 앱의 특정 화면으로 직접 이동시키는 URL입니다.
AdStage SDK는 딥링크 생성, 처리, 추적 기능을 제공합니다.
# pubspec.yaml
dependencies :
nbase_ad_flutter_sdk : ^1.0.1
android/app/src/main/kotlin/.../MainActivity.kt:
import android.content.Intent
import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import io.nbase.adapter.adstage.AdStageSDK
class MainActivity : FlutterActivity () {
override fun onCreate (savedInstanceState: Bundle ?) {
super . onCreate (savedInstanceState)
AdStageSDK. initializeAdStage ( "YOUR_API_KEY" )
}
override fun onNewIntent (intent: Intent ) {
super . onNewIntent (intent)
setIntent (intent)
handleDeepLink (intent)
}
private fun handleDeepLink (intent: Intent ) {
AdStageSDK. handleDeepLink (intent)
}
}
android/app/src/main/AndroidManifest.xml:
< activity
android:name = ".MainActivity"
android:exported = "true"
android:launchMode = "singleTop" >
<!-- 딥링크 인텐트 필터 -->
< intent-filter android:autoVerify = "true" >
< action android:name = "android.intent.action.VIEW" />
< category android:name = "android.intent.category.DEFAULT" />
< category android:name = "android.intent.category.BROWSABLE" />
< data android:scheme = "your-app-scheme" />
</ intent-filter >
</ activity >
ios/Runner/Info.plist:
< key >CFBundleURLTypes</ key >
< array >
< dict >
< key >CFBundleURLName</ key >
< string >nbase-adstage</ string >
< key >CFBundleURLSchemes</ key >
< array >
< string >your-app-scheme</ string >
</ array >
</ dict >
<!-- 필요 시 추가 스킴 등록 가능 -->
</ array >
ios/Runner/AppDelegate.swift:
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate : FlutterAppDelegate {
override func application (
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any ] ?
) -> Bool {
GeneratedPluginRegistrant. register ( with : self )
AdStageSDK.shared. initializeAdStage ( apiKey : "YOUR_API_KEY" )
return super . application (application, didFinishLaunchingWithOptions : launchOptions)
}
}
void _setupDeepLinkListener () {
NbaseAdFlutterSdk .onDeepLinkReceived. listen ((event) {
print ( '딥링크 수신: ${ event . path } ' );
print ( '파라미터: ${ event . parameters } ' );
// 딥링크에 따른 화면 이동
_handleDeepLink (event);
});
}
void _handleDeepLink ( DeepLinkEvent event) {
switch (event.path) {
case '/product' :
Navigator . pushNamed (context, '/product' , arguments : event.parameters);
break ;
case '/user' :
Navigator . pushNamed (context, '/user' , arguments : event.parameters);
break ;
default:
Navigator . pushNamedAndRemoveUntil (context, '/' , (route) => false );
}
}
앱이 종료된 상태에서 딥링크로 실행된 경우, 시작 시 보류 중이던 링크를 확인합니다.
Future < void > checkPendingDeepLink () async {
try {
final result = await NbaseAdFlutterSdk . handleDeepLinkIntent ();
if (result != null ) {
_handleDeepLink (result);
}
} catch (e) {
print ( 'Pending 딥링크 처리 실패: $ e ' );
}
}
@override
void initState () {
super . initState ();
_setupDeepLinkListener ();
// 앱 시작 후 Pending 딥링크 확인
WidgetsBinding .instance. addPostFrameCallback ((_) {
checkPendingDeepLink ();
});
}
딥링크가 수신되지 않음: URL 스킴/도메인 설정 확인, API 키/SDK 초기화 여부 확인
Android 빌드 오류: flutter clean && flutter pub get 후 재빌드, Manifest 설정 확인
iOS 빌드 오류: cd ios && pod install 후 재빌드, Info.plist 설정 확인