אם באפליקציה iOS נעשה שימוש
WKWebView
כדי להציג תוכן מהאינטרנט,
מומלץ להגדיר אותו כך שניתן יהיה לייצר הכנסות מהתוכן באופן אופטימלי באמצעות מודעות.
במדריך הזה מוסבר איך להגדיר
WKWebView
אובייקט.
הגדרות אינטרנט
הגדרות ברירת המחדל של WKWebView
לא עוברות אופטימיזציה להצגת מודעות. כדאי להשתמש
WKWebViewConfiguration
ו-WKWebView
ממשקי API כדי להגדיר את תצוגת האינטרנט עבור המשאבים הבאים:
- הפעלה מתוצאות החיפוש
- הפעלה אוטומטית של סרטון
אי אפשר לראות תצוגות מקדימות לקישורים
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];
}
טעינת תוכן של תצוגת אינטרנט
קובצי Cookie וכתובות 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)
// 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];
}
בדיקה של תצוגת האינטרנט
במהלך פיתוח האפליקציה, מומלץ לטעון את כתובת ה-URL לבדיקה הבאה:
https://webview-api-for-ads-test.glitch.me#webview-settings-tests
כדי לוודא שההגדרות האלה משפיעות על המודעות. כתובת ה-URL לבדיקה כוללת קריטריונים להצלחה לשילוב מלא אם מתקיימים התנאים הבאים:
הגדרות של תצוגה מפורטת של אתר
- קובצי cookie מהדומיין הנוכחי פועלים
- JavaScript מופעל
מודעת וידאו
- מודעת הווידאו מופעלת בתוך השורה ולא נפתחת במסך מלא מובנה נגן
- מודעת הווידאו מופעלת באופן אוטומטי בלי ללחוץ על לחצן ההפעלה
- מודעת הווידאו ניתנת להפעלה חוזרת
בסיום הבדיקה, מחליפים את כתובת ה-URL לבדיקה בכתובת ה-URL של תצוגת האינטרנט מתכוונת להיטען.