إذا كان iOS تطبيقك يستخدم
WKWebView
لعرض محتوى الويب، فهو
ننصحك بضبطها بحيث يمكن تحقيق الربح الأمثل من المحتوى باستخدام الإعلانات
يوضح هذا الدليل كيفية تقديم معلومات حول كيفية تهيئة
WKWebView
.
إعدادات الويب
إعدادات WKWebView
التلقائية غير محسّنة لعرض الإعلانات. استخدام
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)
// 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];
}
تحميل محتوى عرض الويب
ملفات تعريف الارتباط وعناوين 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)
// 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 التجريبي على معايير النجاح للتكامل الكامل في حال رصد ما يلي:
إعدادات عرض الويب
- تعمل ملفات تعريف الارتباط الخاصة بالطرف الأول.
- تم تفعيل JavaScript
إعلان فيديو
- يتم تشغيل إعلان الفيديو بشكل مضمّن ولا يتم فتحه في وضع ملء الشاشة المدمج. لاعب
- يتم تشغيل إعلان الفيديو تلقائيًا بدون النقر على زر التشغيل.
- إعلان الفيديو قابل لإعادة التشغيل
بعد اكتمال الاختبار، استبدِل عنوان URL التجريبي بعنوان URL في عرض الويب. ينوي تحميله.