在 iOS 中初始化 SDK
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.
阅读时间 1 分钟最后更新 a day ago
ViewController.h
在ViewController
.h
- 处理初始化成功或失败的回调。
UnityAdsInitializationDelegate
- 处理广告单元加载内容成功或失败的回调。
UnityAdsLoadDelegate
- 处理广告单元显示加载的内容成功或失败的回调。
UnityAdsShowDelegate
#import <UnityAds/UnityAds.h> @interface ViewController : UIViewController<UnityAdsInitializationDelegate, UnityAdsLoadDelegate, UnityAdsShowDelegate> @property (assign, nonatomic) BOOL testMode;
ViewController.m
要初始化该 SDK,必须为适当平台引用项目的 Game ID(游戏 ID)。在 Monetization(变现)后台的二级导航菜单中选择 CURRENT PROJECT(当前项目)> Settings(设置),即可找到该 ID。 在ViewController
.m
UnityAdsInitializationDelegate
initialize
后续步骤:请参阅关于在 iOS 中实现基本广告的文档以继续您的实现。- (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); }