אם באפליקציה iOS נעשה שימוש בWKWebView
כדי להציג תוכן מהאינטרנט, מומלץ להגדיר אותו כך שניתן יהיה לייצר הכנסות ממנו בצורה אופטימלית באמצעות מודעות.
במדריך הזה מוסבר איך לספק מידע על אופן ההגדרה של אובייקטWKWebView
.
תוכן מדיה
הגדרות ברירת המחדל של WKWebView
לא אופטימליות למודעות וידאו. משתמשים ב-APIs של 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 של דפים חשובים למונטיזציה של צפיות באינטרנט, והם פועלים רק כצפוי כשמשתמשים ב- עם כתובת URL מבוססת רשת. כדי לשפר את WKWebView
הביצועים,
מומלץ מאוד לטעון תוכן באינטרנט מכתובת URL שמבוססת על רשת.
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://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];
[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 שרוצים לטעון את תצוגת האינטרנט.