Initialize the SDK in iOS
Initialize the Unity Ads SDK in your iOS app. Set your Game ID and use a delegate to manage initialization callbacks and enable ad monetization.
Read time 1 minuteLast updated 4 hours ago
ViewController.h
In yourViewController
.h
- handles callbacks for initialization succeeding or failing.
UnityAdsInitializationDelegate
- handles callbacks for Ad Units succeeding or failing to load content.
UnityAdsLoadDelegate
- handles callbacks for Ad Units succeeding or failing to show loaded content.
UnityAdsShowDelegate
#import <UnityAds/UnityAds.h> @interface ViewController : UIViewController<UnityAdsInitializationDelegate, UnityAdsLoadDelegate, UnityAdsShowDelegate> @property (assign, nonatomic) BOOL testMode;
ViewController.m
To initialize the SDK, you must reference your project's Game ID for the appropriate platform. You can locate the ID in the Unity Ads Monetization dashboard by selecting CURRENT PROJECT > Settings from the secondary navigation menu In yourViewController
.m
UnityAdsInitializationDelegate
initialize
Next steps: To continue your implementation, refer to the Implement interstitial ads in iOS documentation.- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [UnityAds initialize:kDefaultGameId testMode:self.testMode initializationDelegate:self]; } // Implement initialization callbacks to handle success or failure: #pragma mark : UnityAdsInitializationDelegate - (void)initializationComplete { NSLog(@" - UnityAdsInitializationDelegate initializationComplete" ); // Pre-load an ad when initialization succeeds, so it is ready to show: [UnityAds load:@"Interstitial_iOS" loadDelegate:self]; } - (void)initializationFailed:(UnityAdsInitializationError)error withMessage:(NSString *)message { NSLog(@" - UnityAdsInitializationDelegate initializationFailed with message: %@", message ); } // Implement load callbacks to handle success or failure after initialization: #pragma mark: UnityAdsLoadDelegate - (void)unityAdsAdLoaded:(NSString *)placementId { NSLog(@" - UnityAdsLoadDelegate unityAdsAdLoaded %@", placementId); } - (void)unityAdsAdFailedToLoad:(NSString *)placementId withError:(UnityAdsLoadError)error withMessage:(NSString *)message { NSLog(@" - UnityAdsLoadDelegate unityAdsAdFailedToLoad %@", placementId); }