Do iOS Get Started all the way until finishing step 5
Add the Initialization code for the SDK
Register all the app UIViewControllers
to the SDK
Add the tagged Wrappers, and tagged Buttons
Note the transition events
Add the testing Single Data
Test everything is working
Change everything to production code
Your app is now prepared for monetization with us.
We require the SDK to be initialized only once and as early as possible It can be done either inside your |
The first recommended place to initialize the SDK is the UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)
method.
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() addTestingSingleTagData() /* This is a later step */ R89SDK.shared.initialize( publisherId: "TestPublisherID", /* This is for testing purposes, change it on prod */ appId: "TestAppId", /* This is for testing purposes, change it on prod */ singleLine: true, publisherInitializationEvents: nil) return true } } |
Your |
This |
Tagged Wrappers are the container inside which the ads will show, they are normal UIView
wrappers with the accessabilityLabel
attribute set. You need to add as many as you can, remember that placing a tagged wrapper does not mean we need to use it.
Check both iOS Creating a wrapper and iOS - Tagged Wrappers for more information.
If the specified |
Events can trigger other formats, right now the single tag supports:
Transition events are detected by the single tag automatically after initialization. They happen when a UIViewController
is started/presented from another UIViewController
.
Button presses are automatically detected by the single tag if the button’s accessibilityLabel
is specified and has a corresponding configuration in the single tag data.
This example demonstrates the automatic display of an interstitial ad during the transition from one screen to another (from InitialScreenViewController
to NewsPostDetailScreenViewController
).
Primarily the transition needs to be configured via the dashboard, but for testing purposes, it could be configured locally by using SingleTagConfigBuilder.shared
instance in your code.
import UIKit import R89SDK @main class AppDelegate: UIResponder, UIApplicationDelegate { ... func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { ... addTestingSingleTagData() /* This is a later step */ R89SDK.shared.initialize(...) return true } func addTestingSingleTagData(){ // Add a Screen that is a UIViewController, the screenName you can get it by logging this in you code -> // in viewDidLoad you can use self.name -> // on InitialScreenViewController -> InitialScreenViewController // on NewsPostDetailScreenViewController -> NewsPostDetailScreenViewController let screenBuilder = SingleTagConfigBuilder.shared .addAdScreenBuilder(isFragment:false,screenName: "InitialScreenViewController") /* trigger interstitial when we transition from "InitialScreenViewController" (ScreenBuilder.screenName) TO NewsPostDetailScreenViewController */ screenBuilder.addInterstitial(eventsToTrackTo: "NewsPostDetailScreenViewController", eventsToTrackButton: nil) ... } ... } |
Hence, the interstitial ad will be displayed whenever InitialScreenViewController
presents InfiniteScrollViewController
.
import UIKit import R89SDK class InitialScreenViewController: UIViewController { ... override func viewDidLoad() { super.viewDidLoad() .. R89SDK.shared.registerLifecycle(uiViewController: self) // Do any additional setup after loading the view. } @IBAction func presentNewsPostDetailScreen(_ sender: UIButton) { // On this transition event, the interstitial ad will be displayed. present(NewsPostDetailScreenViewController(), animated: true) } ... } |
In this example an interstitial would be triggered on top of |
This example shows how an interstitial ad is automatically displayed by intercepting the button press event. After the ad is closed, the button press event is forwarded as expected.
Primarily the button-press needs to be configured via the dashboard, but for testing purposes, it could be configured locally by using SingleTagConfigBuilder.shared
instance in your code.
import UIKit import R89SDK @main class AppDelegate: UIResponder, UIApplicationDelegate { ... func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { ... addTestingSingleTagData() /* This is a later step */ R89SDK.shared.initialize(...) return true } func addTestingSingleTagData(){ let screenBuilder = SingleTagConfigBuilder.shared .addAdScreenBuilder(isFragment:false,screenName: "InitialScreenViewController") ... /* trigger an interstitial when a button with this tag is pressed in "InitialScreenViewControllerj" (ScreenBuilder.screenName) */ screenBuilder.addInterstitial(eventsToTrackTo: nil, eventsToTrackButton: "play_video_trailer_tag") } ... } |
According to the above configuration, the play_video_trailer_tag
must be specified inside the InitialScreenViewController
for the button via the accessibilityLabel
parameter.
Hereafter, the single tag will automatically trigger the display of an interstitial ad when the button press event occurs.
import UIKit import R89SDK class InitialScreenViewController: UIViewController { ... override func viewDidLoad() { super.viewDidLoad() isModalInPresentation = true R89SDK.shared.registerLifecycle(uiViewController: self) // Do any additional setup after loading the view. } // The button's press handler method @IBAction func playVideoTrailer(_ sender: UIButton) { // This method will be called after the interstitial ad is closed. ... } ... } |
In this example an interstitial would be triggered when the button is pressed and when the interstitial is closed the |
Go back to the AppDelegate
class where we initialized the code, we are going to test all the transitions, tagged wrappers, and tagged buttons you have placed in the app.
Before the initialization method, we called addTestingSingleTagData()
which uses the SingleTagConfigBuilder
to create the testing data needed for debugging the SDK.
More info in → https://refinery89.atlassian.net/wiki/x/EgBWTw
When using the |
import UIKit import R89SDK @main class AppDelegate: UIResponder, UIApplicationDelegate { ... func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { ... addTestingSingleTagData() R89SDK.shared.initialize(...) return true } ... func addTestingSingleTagData(){ // Add a Screen that is a UIViewController, the screenName you can get it by logging this in your code -> // in viewDidLoad you can use self.name -> // on InitialScreenViewController -> InitialScreenViewController // on NewsPostDetailScreenViewController -> NewsPostDetailScreenViewController let screenBuilder = SingleTagConfigBuilder.shared.addAdScreenBuilder( isFragment:false, screenName: "InitialScreenViewController") // Add a banner format to the wrapper with the tag bottom_ad_banner_container screenBuilder.addBanner(wrapperTag: "bottom_ad_banner_container", getAllWithTag: false, /* Only the first tagged wrapper in "InitialScreenViewController" with this tag will be used for this banner*/ wrapperRelativePositionInside: true, /* the ad will be placed inside of the wrapper */ wrapperRelativePositionAfter: false) /* trigger interstitial when we transition from "InitialScreenViewController" (ScreenBuilder.screenName) TO NewsPostDetailScreenViewController */ screenBuilder.addInterstitial(eventsToTrackTo: "NewsPostDetailScreenViewController", eventsToTrackButton: nil) /* trigger an interstitial when a button with this tag is pressed in "InitialScreenViewController" (ScreenBuilder.screenName) */ screenBuilder.addInterstitial(eventsToTrackTo: nil, eventsToTrackButton: "play_video_trailer_tag") } ... } |
This step is for testing purposes and you are only going to see test ads when using this approach, but this is very helpful to us if you provide this peace of code to tell us where you want to place the ads. Later when in production, this code have been removed and you have hopefully added flexible tagged wrappers and tagged all the button as possible so we can change your ad slots from the server without the need of updating the app. |
Remove the methods R89SDK.shared.setDebug()
.
Change the GADApplicationIdentifier
in the info.plist
for the production one.
Change the appId
and publisherId
in the initialization method for the production ones.
it’s also recommended to remove R89SDK.shared.setLogLevel(level: LogLevels.debug)
but not needed.
We monitor your app to determine the active screen at any given moment. For each screen, we maintain a record of events and tags that you have supplied, enabling us to place ads in those tagged views or during specific transitions and events from the record.
We have the capability to display Display ads on a tagged wrappers or trigger an Interstitial ads during the transition from one screen to another or in button press. And many other things All of this can be achieved without the need of coding specific triggers or manually adding the ad to the view. It is as simple as initializing the SDK.