הגדרת WKWebView

אם האפליקציה שלכם משתמשת ב- WKWebView כדי להציג תוכן אינטרנטי, מומלץ להגדיר אותה כך שניתן יהיה לייצר הכנסות מהתוכן בצורה אופטימלית באמצעות מודעות.

במדריך הזה מוסבר איך לספק מידע על הגדרה של אובייקט WKWebView.

תוכן מדיה

ההגדרות שמוגדרות כברירת מחדל WKWebView לא מותאמות למודעות וידאו. משתמשים בממשקי ה-API של WKWebViewConfiguration כדי להגדיר את WKWebView להפעלה מוטבעת ולהפעלה אוטומטית של סרטונים.

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)
    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];
  [self.view addSubview:self.webView];
}

טעינת תוכן בתצוגת אינטרנט

קובצי Cookie וכתובות URL של דפים חשובים למונטיזציה של תצוגת אינטרנט, והם פועלים כמצופה רק כשמשתמשים ב-load(_:) עם כתובת URL מבוססת-רשת. כדי ליהנות מביצועים אופטימליים, מומלץ מאוד לטעון תוכן אינטרנט מכתובת URL מבוססת-רשת.WKWebView

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)
    view.addSubview(webView)

    // Load the URL for optimized web view performance.
    guard let url = URL(string: "https://google.github.io/webview-ads/test/") 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];
  [self.view addSubview:self.webview];

  // Load the URL for optimized web view performance.
  NSURL *url = [NSURL URLWithString:@"https://google.github.io/webview-ads/test/"];
  NSURLRequest *request = [NSURLRequest requestWithURL:url];
  [webView loadRequest:request];
}

בדיקת תצוגת האינטרנט

במהלך פיתוח האפליקציה, מומלץ לטעון את כתובת ה-URL לבדיקה הזו:

https://google.github.io/webview-ads/test/

כדי לוודא שההגדרות האלה משפיעות על המודעות כמו שרציתם. כתובת ה-URL לבדיקה כוללת קריטריונים להצלחה של שילוב מלא אם מתקיימים התנאים הבאים:

הגדרות של תצוגת אינטרנט

  • איך קובצי Cookie מהדומיין הנוכחי פועלים
  • ‫JavaScript מופעל

מודעת וידאו

  • מודעת הווידאו מוצגת בתוך השורה ולא נפתחת בנגן המובנה במסך מלא
  • מודעת הווידאו מופעלת אוטומטית בלי ללחוץ על לחצן ההפעלה
  • מודעת הווידאו ניתנת להפעלה חוזרת

אחרי שהבדיקה מסתיימת, מחליפים את כתובת ה-URL לבדיקה בכתובת ה-URL שאותה התצוגה המקדימה באינטרנט אמורה לטעון.