네이티브 광고
네이티브 광고는 광고가 게재되는 사용자 환경의 형식 및 기능에 맞춰 자동으로 최적화되어 출력 됩니다.
1. 위젯 생성
네이티브를 추가하고자 하는 위치에 아래의 위젯을 생성하여 등록합니다.
Android의 경우 AndroidView 내 아래 설정을 반드시 추가합니다.
ViewType : ‘AdPopcornSSPNativeView’
creationParams
appKey
placementId
width (optional, only Android)
height (optional, only Android) : 광고 영역보다 크거나 작은 영역을 광고 영역으로 잡을 경우 정확한 정렬을 위해서 android의 height는 Container의 height와 동일한 값을 넣어주시기 바랍니다
Widget _setNativeView() {
const String viewType = 'AdPopcornSSPNativeView';
if (Platform.isAndroid) {
final Map<String, dynamic> creationParams = <String, dynamic>
{'appKey':'your_app_key', 'placementId':'your_placement_id', 'height':280};
return Container(
width: double.maxFinite,
height:280,
child: AndroidView(
viewType: viewType,
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
),
);
}
else if (Platform.isIOS) {
final Map<String, dynamic> creationParams = <String, dynamic>
{'appKey':'your_app_key', 'placementId':'your_placement_id'};
return Container(
width: double.maxFinite,
height:280,
child: UiKitView(
viewType: viewType,
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
),
);
}
else{
return Container(
width: double.maxFinite,
height: 1
);
}
}
2. MethodChannel 생성
네이티브의 이벤트를 전달 받고 싶은 경우, 아래의 규칙으로 method channel을 생성합니다.
MethodChannel
('adpopcornssp/{your_placement_id}
')
생성한 MethodChannel에 methodCallHandler
를 세팅할 경우, 아래 이벤트를 전달 받을 수 있습니다.
이벤트
설명
APSSPNativeAdLoadSuccess
네이티브 광고 로드 성공
APSSPNativeAdLoadFail
네이티브 광고 로드 실패. 에러코드 값
APSSPNativeAdImpression
네이티브 광고 노출 성공
APSSPNativeAdClicked
네이티브 광고 클릭
class _MyAppState extends State<MyApp> {
static const MethodChannel androidNativeChannel = const MethodChannel('adpopcornssp/your_placement_id');
static const MethodChannel iosNativeChannel = const MethodChannel('adpopcornssp/your_placement_id');
@override
void initState() {
super.initState();
if (Platform.isAndroid) {
AdPopcornSSP.init('663451319');
// 네이티브 이벤트 채널 연동
androidBannerChannel.setMethodCallHandler(_eventHandleMethod);
} else if (Platform.isIOS) {
AdPopcornSSP.init('397261446');
// 네이티브 이벤트 채널 연동
iosNativeChannel.setMethodCallHandler(_eventHandleMethod);
}
}
static Future<dynamic> _eventHandleMethod(MethodCall call) {
final Map<dynamic, dynamic> arguments = call.arguments;
final String method = call.method;
final String placementId = arguments['placementId'];
if (method == 'APSSPNativeAdLoadSuccess') {
} else if (method == 'APSSPNativeAdLoadFail') {
final int errorCode = arguments['errorCode'];
} else if (method == 'APSSPNativeAdImpression') {
} else if (method == 'APSSPNativeAdClicked') {
}
return Future<dynamic>.value(null);
}
}
Last updated
Was this helpful?