Prerequisites
Do iOS Get Started all the way until finishing step 3
Step Summary
Add The initialization code.
Create the Channel between web and native with
configureWebView()
methodUse
loadUrlWithConsentDataOrWait
to load your urls into the webviewTest everything is working
Change everything to production cod
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) ... } }
Load URLs with consent
Use the following method to replace any webview.load()
methods you might have
R89SDK.shared.loadUrlWithConsentDataOrWait(webView: wkWebView, url: url)
This url must only be the urls related to you content, or own. Other urls can be loaded normally. with webview.loadUrl()
Go into production
Remove the methods
R89SDK.shared.setDebug()
.Change the
GADApplicationIdentifier
in theinfo.plist
for the production one.Change the
appId
andpublisherId
in the initialization method for the production ones.Change the
r89ConfigId
in the formats for the production ones.it’s also recommended to remove
R89SDK.shared.setLogLevel(level: LogLevels.debug)
but not needed.
How does it work?
Works by creating a channel linking our SDK to your current in-web monetization solutions. This channel just makes sure that the ad units on the web know that the current environment is app and also sends the consent data so you get the same consent on both sides complying with privacy policies.