iOS Standalone Ad
Learn how to create additional content monetization opportunities in your iOS app
Standalone Ads enables you to customize ad opportunities and augment the revenue potential of your app:
- Create new high-profile ad opportunities of any dimensions
- Display video and display ads
- Enforce brand safety
Prerequisites
- iOS 13.0+
- Xcode 15.3+
- CocoaPods 1.12+
- Google Mobile Ads App ID
- Google Mobile Ads SKAdNetworkIdentifier
Install the dependencies
Use the following steps to install the dependencies:
-
In a text editor, open Podfile.
-
Update Podfile with the following information.
use_frameworks! target 'YOUR_APP_TARGET' do pod 'OpenWebIAU', '<<iOSStandaloneAdVersion>>' end post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| if target.name == 'NimbusSDK' config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES' end end end end
-
From the terminal prompt, run
pod install --repo-update
in your project directory to install the pod.
Update the Info.plist file
Add the keys listed below to the Info.plist file of your app.
Key | Description |
---|---|
GADApplicationIdentifier | Google Mobile Ads app ID |
SKAdNetworkIdentifier | Ad network identifier |
NSUserTrackingUserDescription | Description displayed in the app tracking transparency prompt to the user This custom message is shown to the user when requesting access to the IDFA. |
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Google Mobile Ads Configuration -->
<key>GADApplicationIdentifier</key>
<string>Your-Google-Mobile-Ads-App-ID</string>
<!-- App Tracking Transparency -->
<key>NSUserTrackingUsageDescription</key>
<string>This app will use your data to provide better ad experience.</string>
<!-- SKAdNetwork Configuration -->
<key>SKAdNetworkItems</key>
<array>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>example.skadnetwork</string>
</dict>
</array>
</dict>
</plist>
Implement EU User Consent
Implementing EU User Consent in your app demonstrates a commitment to user privacy and trust.
You can use either of the following approaches to implement user consent:
Manual Consent Form
This approach shows a user consent form, obtains user consent, and sets the GDPR settings in the SpotIM SDK based on the user's response.
- Show the user consent form.
- With the return consent form results, call the following methods.
SpotImAds.setGdprRequired(...) SpotImAds.setGdprConsentString(...)
CMP SDK
This approach leverages a Consent Management Platform (CMP) SDK, which handles the user consent process. The GDPR applicability and consent information are stored in standard UserDefaults
keys and can be retrieved to configure the SpotIM SDK.
When using a CMP SDK such as Google UMP, you can implement the following code.
let isGdprRequired = UserDefaults.standard.bool(forKey: "IABTCF_gdprApplies")
SpotImAds.setGdprRequired(required: isGdprRequired)
if isGdprRequired,
let consent = UserDefaults.standard.string(forKey: "IABTCF_TCString") {
SpotImAds.setGdprConsentString(consent: consent)
}
Initialize the SDK
In the AppDelegate
, initialize the SpotIM SDK.
import SpotImStandaloneAds
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(...) -> Bool
SpotImAds.initSDK(
spotId: ..., // your spotim id
storeURL: ... // your App Store url
)
return true
}
}
Display an ad
-
Show the tracking authorization dialog before showing ads.
import AppTrackingTransparency import AdSupport ... // AppDelegate::applicationDidBecomeActive, or: // UIViewController::viewDidLoad (provided it happens after applicationDidBecomeActive) ATTrackingManager.requestTrackingAuthorization { status in // Tracking authorization completed. Start loading ads here. }
-
Insert an ad slot to display an ad.
import SpotImStandaloneAds class YourViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let child = SpotImAds.makePlacement(row: 1, column: 1) addChild(child) view.addSubview(child.view) child.view.translatesAutoresizingMaskIntoConstraints = false /// <---- Add constraints /// NOTE: height contraint is managed by SDK or by sizeDelegate child.didMove(toParent: self) child.sizeDelegate = self /// Optional. Custom size handling } }
When ads are preloaded, users are more likely to see already loaded or nearly ready ads when scrolling to the ad slot.
To preload ads, make the following call.
// Some Page (ViewController) // ViewDidLoad SpotImAds.preload( row: row, column: column, analyticsInfo: .init( // optional. Needed for improving Analytics url: "/home/articles", postId: "123" ) )
Updated 2 months ago