WKWebView सेट अप करें

अगर आपका 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];
}

वेब व्यू कॉन्टेंट लोड करें

कुकी और पेज के यूआरएल, वेब व्यू से कमाई करने के लिए ज़रूरी हैं. साथ ही, ये सिर्फ़ काम करते हैं उम्मीद के मुताबिक जब का इस्तेमाल नेटवर्क का यूआरएल. ऑप्टिमाइज़ की गई 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];
}

वेब व्यू की जांच करना

ऐप्लिकेशन डेवलपमेंट के दौरान, हमारा सुझाव है कि आप इस टेस्ट यूआरएल को लोड करें:

https://webview-api-for-ads-test.glitch.me#webview-settings-tests

ताकि विज्ञापनों पर इन सेटिंग के सही असर की पुष्टि की जा सके. टेस्ट यूआरएल में अगर नीचे दी गई बातों का ध्यान रखा जाता है, तो एक पूरे इंटिग्रेशन की सफलता का मानदंड तय होगा:

वेब व्यू की सेटिंग

  • पहले-पक्ष की कुकी काम करती हैं
  • JavaScript चालू है

वीडियो विज्ञापन

  • वीडियो विज्ञापन इनलाइन चलता है और बिल्ट-इन फ़ुल स्क्रीन में नहीं खुलता है खिलाड़ी
  • वीडियो विज्ञापन बिना चलाएं बटन पर क्लिक किए अपने आप चलता है
  • वीडियो विज्ञापन को फिर से चलाया जा सकता है

जांच पूरी होने के बाद, टेस्ट यूआरएल को वेब व्यू के यूआरएल से बदलें लोड करना चाहता है.