Jeśli aplikacja iOS korzysta
WKWebView
wyświetlanie treści z internetu
zalecamy jego skonfigurowanie w taki sposób, aby optymalnie zarabiać na reklamach w treściach.
W tym przewodniku opisujemy, jak podać informacje na temat konfigurowania
WKWebView
obiektów.
Ustawienia internetowe
Domyślne ustawienia funkcji WKWebView
nie są zoptymalizowane pod kątem reklam. Używaj
WKWebViewConfiguration
i API WKWebView
do skonfigurowania widoku internetowego dla tych zasobów:
- Odtwarzanie w treści
- Automatyczne odtwarzanie wideo
Nie zezwalam na podgląd linków
Swift
import WebKit
class ViewController: UIViewController {
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Initialize a WKWebViewConfiguration object.
let webViewConfiguration = 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)
// Links opened using link preview don't call web view delegates. Ensure
// delegates are always called on clicks by disabling link preview.
webView.allowsLinkPreviews = false
view.addSubview(webView)
}
}
Objective-C
@import WebKit;
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic, strong) WKWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize a WKWebViewConfiguration object.
WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] 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 = [[WKWebView alloc] initWithFrame:self.view.frame configuration:webViewConfiguration];
// Links opened using link preview don't call web view delegates. Ensure
// delegates are always called on clicks by disabling link preview.
self.webView.allowsLinkPreviews = NO;
[self.view addSubview:self.webView];
}
Wczytaj treść widoku internetowego
Pliki cookie i adresy URL stron są ważne dla zarabiania na wyświetleniach stron internetowych i działają tylko
zgodnie z oczekiwaniami, gdy jest używany z
oparty na sieci. Aby zoptymalizować WKWebView
wydajność,
zdecydowanie zalecamy wczytywanie treści z adresu URL działającego w sieci.
Swift
import WebKit
var webview: WKWebview!
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Initialize a WKWebViewConfiguration object.
let webViewConfiguration = 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)
// Links opened using link preview don't call web view delegates. Ensure
// delegates are always called on clicks by disabling link preview.
webView.allowsLinkPreviews = false
view.addSubview(webView)
// Load the URL for optimized web view performance.
guard let url = URL(string: "https://webview-api-for-ads-test.glitch.me") else { return }
let request = URLRequest(url: url)
webView.load(request)
}
}
Objective-C
@import WebKit;
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic, strong) WKWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize a WKWebViewConfiguration object.
WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] 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 = [[WKWebView alloc] initWithFrame:self.view.frame configuration:webViewConfiguration];
// Links opened using link preview don't call web view delegates. Ensure
// delegates are always called on clicks by disabling link preview.
self.webView.allowsLinkPreviews = NO;
[self.view addSubview:self.webview];
// Load the URL for optimized web view performance.
NSURL *url = [NSURL URLWithString:@"https://webview-api-for-ads-test.glitch.me"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
Testowanie widoku internetowego
Podczas tworzenia aplikacji zalecamy wczytanie tego testowego adresu URL:
https://webview-api-for-ads-test.glitch.me#webview-settings-tests
aby sprawdzić, czy te ustawienia mają zamierzony wpływ na reklamy. Testowy adres URL zawiera są spełnione te warunki:
Ustawienia widoku internetowego
- Własne pliki cookie działają
- JavaScript włączony
Reklama wideo
- Reklama wideo jest odtwarzana w treści i nie otwiera się na pełnym ekranie zawodnik
- Reklama wideo odtwarza się automatycznie bez klikania przycisku odtwarzania
- Reklamę wideo można ponownie odtworzyć
Po zakończeniu testowania zastąp testowy adres URL adresem URL widoku witryny. który chce się załadować.