쿠팡 클릭 이벤트 페이지 연동 가이드
쿠팡 브릿지 이벤트 페이지 연동을 위한 가이드입니다.
1. 이벤트 페이지 URL 연동
https://click-reward.adpopcorn.com/kakaopay/
이벤트 페이지 URL은 매체별로 구분됩니다.
이벤트 페이지의 주소는 사업팀(pm@adpopcorn.com)을 통해 전달됩니다.
2. 웹뷰 내 JavascriptInterface 설정
이벤트 페이지의 원활한 동작을 위해 아래 가이드를 참고하여 JavascriptInterface 설정을 진행해 주어야 합니다.
2.1 공통 사항
호출은 APSSPClickReward 객체로 호출합니다. 이에 아래와 같이 각 OS 환경에 맞게 APSSPClickReward 를 등록해 주어야 합니다.
webView = new WebView(context.getApplicationContext());
webView.addJavascriptInterface(this, "APSSPClickReward");
wkContentController = [[WKUserContentController alloc]init];
[wkContentController addScriptMessageHandler:self name:@"APSSPClickReward"];
webViewConfiguration = [[WKWebViewConfiguration alloc]init];
webViewConfiguration.userContentController = wkContentController;
webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) configuration:webViewConfiguration];
2.2 Interfaces
2.2.1 closeWebView()
설명 : 이벤트 페이지의 상단 백버튼 클릭 시, 호출되며 현재의 웹뷰 화면을 종료 처리해 주어야 합니다.
아래 샘플 코드를 참고해, 매체사의 개발환경에 맞게 변형하여 처리해 줍니다.
@JavascriptInterface
public void closeWebView(){
finish();
}
#pragma mark WKUIDelegate
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message
{
if([message.name isEqualToString:@"APSSPClickReward"]){
id JSON;
if ([[message body] isKindOfClass:[NSString class]]) {
id strJson = [message body];
NSData *nsData = [strJson dataUsingEncoding:NSUTF8StringEncoding];
JSON = [NSJSONSerialization JSONObjectWithData:nsData options:0 error:nil];
}
else
{
JSON = [message body];
}
NSString *action = [self checkNilToBlankString:[JSON valueForKey:@"action"]];
if([action isEqualToString:@"closeWebView"])
{
[webView loadHTMLString:@"" baseURL:nil];
[webView stopLoading];
webView.UIDelegate = nil;
webView.navigationDelegate = nil;
[webView removeFromSuperview];
webView = nil;
[self.navigationController popViewControllerAnimated:NO];
}
}
}
- (NSString *)checkNilToBlankString:(id)target
{
NSString *returnString = @"";
if (!([target isEqual:[NSNull null]] || target == nil))
{
returnString = target;
}
return returnString;
}
2.3 쿠팡 광고 클릭에 대한 처리
아래 설정이 누락될 경우, 광고 클릭 시, 웹뷰 내에서 광고 페이지로 랜딩됩니다. 이에 반드시 연동을 진행해 주어야 합니다.
private void setWebViewSetting(){
webView = new WebView(context.getApplicationContext());
webView.addJavascriptInterface(this, "APSSPClickReward");
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Intent intent = new Intent(Intent.ACTION_VIEW, request.getUrl());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
return true;
}
});
}
#pragma mark WKUIDelegate
- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
NSString *requestString = navigationAction.request.URL.absoluteString;
if(navigationAction.navigationType == WKNavigationTypeLinkActivated ||
navigationAction.navigationType == WKNavigationTypeOther)
{
NSURL *requestURL = [NSURL URLWithString:requestString];
if(@available(iOS 10, *))
{
[[UIApplication sharedApplication] openURL:requestURL options:@{} completionHandler:^(BOOL success) {
if (success) {
[_webView stopLoading];
}
}];
}
else
{
[[UIApplication sharedApplication] openURL:requestURL];
[_webView stopLoading];
}
}
return nil;
}
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
NSString *requestString = navigationAction.request.URL.absoluteString;
if(navigationAction.navigationType == WKNavigationTypeLinkActivated)
{
decisionHandler(WKNavigationActionPolicyCancel);
NSURL *requestURL = [NSURL URLWithString:requestString];
if(@available(iOS 10, *))
{
[[UIApplication sharedApplication] openURL:requestURL options:@{} completionHandler:^(BOOL success) {
if (success) {
[_webView stopLoading];
}
}];
}
else
{
[[UIApplication sharedApplication] openURL:requestURL];
[_webView stopLoading];
}
return;
}
decisionHandler(WKNavigationActionPolicyAllow);
}
Last updated
Was this helpful?