Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 4 Next »

Prerequisites

Step Summary

  1. Add The initialization code.

  2. Create the Channel between web and native with configureWebView() method

  3. Use loadUrlWithConsentDataOrWait to load your urls into the webview

  4. Test everything is working

  5. Change everything to production cod

  6. Your app is now prepared for monetization with us.

Remember that you should be using our CMP also in web so consent data can be understood.

If you are placing all or some ads natively, meaning that the actions on the web view trigger native code through some kind of javascript interface, then we recommend using Manual Implementation or if you are displaying some ads inside the webview and others in the native app you can use this implementation and the manual together to make this happen.

Initialize the SDK

We require the SDK to be initialized only once as early as possible so for this purpose using the UIApplicationDelegate’s didFinishLaunchingWithOptions method or the first UIViewController’s viewDidLoad method is recomended.

Override the didFinishLaunchingWithOptions delegate method inside your UIApplicationDelegate class.

import UIKit
import R89SDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // This is for testing purposes, remove it on prod
        R89SDK.shared.setLogLevel(level: LogLevels.debug)
        // This is for testing purposes, remove it on prod
        R89SDK.shared.setDebug() // This is for testing purposes, remove it on prod
        // publisherId and appId are for testing purposes, remove it on prod
        R89SDK.shared.initialize(
          publisherId: "TestRefinery89ID",
          appId: "TestDemoApp",
          singleLine: false,
          publisherInitializationEvents: nil
        )
        return true
    }
}

Your publisherId and appId will be provided to you during onboarding process by email, you can also retrieve them from the web interface after login.

This appID is not the same GADApplicationIdentifier provided in the Info.plist in previous steps.

Until here is the same as the Manual implementation, this is why this implementation is compatible with the manual, but now instead of focusing on wrappers, events, and formats we will see how to create the channel and how to load URLs to have consent in them.

If you want to have native ads to be triggered from the webview we recommend using the manual configuration alongside some kind of javascript interface implemented in the web side to trigger native code, although first finish this whole guide and then go to the manual

Create the Channel

Right after Initialization, you should use the following methods

import UIKit
import R89SDK
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {
    
    @IBOutlet var wkWebView: WKWebView!
    ...

    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        let url = <YOUR-URL>
      
        wkWebView.navigationDelegate = self
        
        // This helps the channel to identify this as an app
        let userAgent = R89SDK.shared.getUserAgent(
                          webView: wkWebView, 
                          siteName: <YOUR-SITE-NAME>)
        
        R89SDK.shared.configureWebView(webView: wkWebView, userAgent: userAgent)
        
        R89SDK.shared.loadUrlWithConsentDataOrWait(webView: wkWebView, url: url)        
    }

    func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
        R89SDK.shared.addScriptToNotShowCMPInWebView(webView: webView)
    }
}

  • No labels