앱에서 WKWebView를 사용하여 웹 콘텐츠를 표시하는 경우 광고를 통해 콘텐츠를 최적으로 수익 창출할 수 있도록 구성하는 것이 좋습니다.
이 가이드에서는 WKWebView 객체를 구성하는 방법에 관한 정보를 제공하는 방법을 보여줍니다.
미디어 콘텐츠
기본 WKWebView 설정이 동영상 광고에 최적화되어 있지 않습니다. WKWebViewConfiguration
API를 사용하여 인라인 재생 및 자동 동영상 재생을 위해 WKWebView을(를) 구성합니다.
Swift
importWebKitclassViewController:UIViewController{varwebView:WKWebView!overridefuncviewDidLoad(){super.viewDidLoad()// Initialize a WKWebViewConfiguration object.letwebViewConfiguration=WKWebViewConfiguration()// Let HTML videos with a "playsinline" attribute play inline.webViewConfiguration.allowsInlineMediaPlayback=true// Let HTML videos with an "autoplay" attribute play automatically.webViewConfiguration.mediaTypesRequiringUserActionForPlayback=[]// Initialize the WKWebView with your WKWebViewConfiguration object.webView=WKWebView(frame:view.frame,configuration:webViewConfiguration)view.addSubview(webView)}}
Objective-C
@importWebKit;#import "ViewController.h"@interfaceViewController()@property(nonatomic,strong)WKWebView*webView;@end@implementationViewController-(void)viewDidLoad{[superviewDidLoad];// Initialize a WKWebViewConfiguration object.WKWebViewConfiguration*webViewConfiguration=[[WKWebViewConfigurationalloc]init];// Let HTML videos with a "playsinline" attribute play inline.webViewConfiguration.allowsInlineMediaPlayback=YES;// Let HTML videos with an "autoplay" attribute play automatically.webViewConfiguration.mediaTypesRequiringUserActionForPlayback=WKAudiovisualMediaTypeNone;// Initialize the WKWebView with your WKWebViewConfiguration object.self.webView=[[WKWebViewalloc]initWithFrame:self.view.frameconfiguration:webViewConfiguration];[self.viewaddSubview:self.webView];}
웹 뷰 콘텐츠 로드
쿠키와 페이지 URL은 웹 뷰 수익 창출에 중요하며, load(_:)이 네트워크 기반 URL과 함께 사용될 때만 예상대로 작동합니다. WKWebView 성능을 최적화하려면 네트워크 기반 URL에서 웹 콘텐츠를 로드하는 것이 좋습니다.
Swift
importWebKitvarwebview:WKWebview!classViewController:UIViewController{overridefuncviewDidLoad(){super.viewDidLoad()// Initialize a WKWebViewConfiguration object.letwebViewConfiguration=WKWebViewConfiguration()// Let HTML videos with a "playsinline" attribute play inline.webViewConfiguration.allowsInlineMediaPlayback=true// Let HTML videos with an "autoplay" attribute play automatically.webViewConfiguration.mediaTypesRequiringUserActionForPlayback=[]// Initialize the WKWebView with your WKWebViewConfiguration object.webView=WKWebView(frame:view.frame,configuration:webViewConfiguration)view.addSubview(webView)// Load the URL for optimized web view performance.guardleturl=URL(string:"https://google.github.io/webview-ads/test/")else{return}letrequest=URLRequest(url:url)webView.load(request)}}
Objective-C
@importWebKit;#import "ViewController.h"@interfaceViewController()@property(nonatomic,strong)WKWebView*webView;@end@implementationViewController-(void)viewDidLoad{[superviewDidLoad];// Initialize a WKWebViewConfiguration object.WKWebViewConfiguration*webViewConfiguration=[[WKWebViewConfigurationalloc]init];// Let HTML videos with a "playsinline" attribute play inline.webViewConfiguration.allowsInlineMediaPlayback=YES;// Let HTML videos with an "autoplay" attribute play automatically.webViewConfiguration.mediaTypesRequiringUserActionForPlayback=WKAudiovisualMediaTypeNone;// Initialize the WKWebView with your WKWebViewConfiguration object.self.webView=[[WKWebViewalloc]initWithFrame:self.view.frameconfiguration:webViewConfiguration];[self.viewaddSubview:self.webview];// Load the URL for optimized web view performance.NSURL*url=[NSURLURLWithString:@"https://google.github.io/webview-ads/test/"];NSURLRequest*request=[NSURLRequestrequestWithURL:url];[webViewloadRequest:request];}
[null,null,["최종 업데이트: 2025-09-02(UTC)"],[[["\u003cp\u003eTo optimize iOS app monetization with ads in WKWebView, configure it for inline video playback and automatic play.\u003c/p\u003e\n"],["\u003cp\u003eLoad web content using network-based URLs for optimal WKWebView performance and monetization.\u003c/p\u003e\n"],["\u003cp\u003eIf loading content from other sources, include the Publisher Provided Identifier (PPID) and page URL to minimize monetization impact.\u003c/p\u003e\n"],["\u003cp\u003eUse the provided test URL during development to verify settings and ad functionality before replacing it with your intended URL.\u003c/p\u003e\n"]]],["To optimize `WKWebView` for ad monetization, configure each instance with `WKWebViewConfiguration`. Enable inline playback for HTML videos using `allowsInlineMediaPlayback = true`, and allow automatic video play by setting `mediaTypesRequiringUserActionForPlayback` to an empty array (Swift) or `WKAudiovisualMediaTypeNone` (Objective-C). Load web content using `load(_:)` with a network-based URL for proper cookie and URL functionality. During development, test with `https://webview-api-for-ads-test.glitch.me#webview-settings-tests` to verify cookie, JavaScript, inline, autoplay, and replayable video ad settings.\n"],null,["If your app utilizes `\n`[WKWebView](//developer.apple.com/documentation/webkit/wkwebview) to display web content, it's\nrecommended to configure it so that content can be optimally monetized with ads.\n\nThis guide shows you how to provide information about how to configure a\n`WKWebView` object.\n| **Important:** To properly set up and optimize `WKWebView`, apply all of the following recommendations to each `WKWebView` instance in your app.\n\nMedia Content\n\nDefault `WKWebView` settings are not optimized for video ads. Use the\n[`WKWebViewConfiguration`](//developer.apple.com/documentation/webkit/wkwebviewconfiguration)\nAPIs to configure your `WKWebView` for inline playback and automatic video play. \n\nSwift \n\n import WebKit\n\n class ViewController: UIViewController {\n\n var webView: WKWebView!\n\n override func viewDidLoad() {\n super.viewDidLoad()\n\n // Initialize a WKWebViewConfiguration object.\n let webViewConfiguration = WKWebViewConfiguration()\n // Let HTML videos with a \"playsinline\" attribute play inline.\n webViewConfiguration.allowsInlineMediaPlayback = true\n // Let HTML videos with an \"autoplay\" attribute play automatically.\n webViewConfiguration.mediaTypesRequiringUserActionForPlayback = []\n\n // Initialize the WKWebView with your WKWebViewConfiguration object.\n webView = WKWebView(frame: view.frame, configuration: webViewConfiguration)\n view.addSubview(webView)\n }\n }\n\nObjective-C \n\n @import WebKit;\n\n #import \"ViewController.h\"\n\n @interface ViewController ()\n\n @property(nonatomic, strong) WKWebView *webView;\n\n @end\n\n @implementation ViewController\n\n - (void)viewDidLoad {\n [super viewDidLoad];\n\n // Initialize a WKWebViewConfiguration object.\n WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] init];\n // Let HTML videos with a \"playsinline\" attribute play inline.\n webViewConfiguration.allowsInlineMediaPlayback = YES;\n // Let HTML videos with an \"autoplay\" attribute play automatically.\n webViewConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;\n\n // Initialize the WKWebView with your WKWebViewConfiguration object.\n self.webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:webViewConfiguration];\n [self.view addSubview:self.webView];\n }\n\nLoad web view content\n\nCookies and page URLs are important for web view monetization and only function\nas expected when\n[`load(_:)`](//developer.apple.com/documentation/webkit/wkwebview/1414954-load) is used with a network-based URL. For optimized\n`WKWebView` performance,\nwe strongly recommend loading web content from a network-based URL.\n\n\nSwift \n\n import WebKit\n\n var webview: WKWebview!\n\n class ViewController: UIViewController {\n override func viewDidLoad() {\n super.viewDidLoad()\n\n // Initialize a WKWebViewConfiguration object.\n let webViewConfiguration = WKWebViewConfiguration()\n // Let HTML videos with a \"playsinline\" attribute play inline.\n webViewConfiguration.allowsInlineMediaPlayback = true\n // Let HTML videos with an \"autoplay\" attribute play automatically.\n webViewConfiguration.mediaTypesRequiringUserActionForPlayback = []\n\n // Initialize the WKWebView with your WKWebViewConfiguration object.\n webView = WKWebView(frame: view.frame, configuration: webViewConfiguration)\n view.addSubview(webView)\n\n // Load the URL for optimized web view performance.\n guard let url = URL(string: \"https://google.github.io/webview-ads/test/\") else { return }\n let request = URLRequest(url: url)\n webView.load(request)\n }\n }\n\nObjective-C \n\n @import WebKit;\n\n #import \"ViewController.h\"\n\n @interface ViewController ()\n\n @property(nonatomic, strong) WKWebView *webView;\n\n @end\n\n @implementation ViewController\n\n - (void)viewDidLoad {\n [super viewDidLoad];\n\n // Initialize a WKWebViewConfiguration object.\n WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] init];\n // Let HTML videos with a \"playsinline\" attribute play inline.\n webViewConfiguration.allowsInlineMediaPlayback = YES;\n // Let HTML videos with an \"autoplay\" attribute play automatically.\n webViewConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;\n\n // Initialize the WKWebView with your WKWebViewConfiguration object.\n self.webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:webViewConfiguration];\n [self.view addSubview:self.webview];\n\n // Load the URL for optimized web view performance.\n NSURL \\*url = \\[NSURL URLWithString:@\"https://google.github.io/webview-ads/test/\"\\];\n NSURLRequest \\*request = \\[NSURLRequest requestWithURL:url\\];\n \\[webView loadRequest:request\\];\n }\n\n| **Tip:** If you need to load web view content from others means, such as HTML, you can mitigate the negative impact on monetization by transmitting the [Publisher Provided Identifier](//support.google.com/admanager/answer/2880055#setting_the_identifier) (PPID) and the relevant page URL ([GPT](/publisher-tag/guides/passback-tags#specify_page_url) \\| [AdSense](/adsense/management/reference/rest/v2/Dimension)) along with your web view request. These changes mitigate the monetization loss compared to loading web content from a network-based URL.\n\nTest the web view\n\nDuring app development, we recommend that you load this test URL: \n\n https://google.github.io/webview-ads/test/\n\nto verify these settings have the intended effect on ads. The test URL has\nsuccess criteria for a complete integration if the following are observed:\n\nWeb view settings\n\n- First-party cookies work\n- JavaScript enabled\n\nVideo ad\n\n- The video ad plays inline and does not open in the full screen built-in player\n- The video ad plays automatically without clicking the play button\n- The video ad is replayable\n\nAfter testing is complete, substitute the test URL with the URL the web view\nintends to load."]]