AdMob
1. 기본 요건
ADX iOS SDK를 프로젝트에 추가합니다.
Rewarded Ad용으로 발급받은 AdMob Ad Unit ID를 사용합니다.
광고를 요청하기 전에 SDK 초기화를 먼저 진행해야 합니다.
SDK 초기화는 앱 실행 시 한 번만 호출하여 주시고, 광고 요청은 초기화가 완료된 후에 이뤄져야 합니다.
iOS 14 이상 지원하는 경우, ATT(App Tracking Transparency) 권한 요청 완료 후 광고를 요청해주세요.
Info.plist
파일에GADApplicationIdentifier
키와 발급된 AdMob APP ID를 추가합니다.GADApplicationIdentifier
를 추가하지 않으면 다음 메시지가 표시되며 앱이 비정상 종료됩니다.The Google Mobile Ads SDK was initialized incorrectly.
<key>GADApplicationIdentifier</key> <string>ADMOB_APP_ID</string>
2. 구현
GADRequest
를 생성합니다.GDPR 관련 규정을 준수하는 경우, 사용자가 개인정보 활용 및 수집을 거부한 상태(
ADXConsentStateDenied
)일 때npa
를1
로 추가합니다.
GADRewardedAd
의loadWithAdUnitID:request:completionHandler:
메서드로 광고를 로드합니다.광고 로드가 완료되면
GADFullScreenContentDelegate
callback을 등록합니다.GADRewardedAd
의presentFromRootViewController:userDidEarnRewardHandler:
로 광고를 표시합니다.광고 시청을 모두 완료하면
GADUserDidEarnRewardHandler
객체에서 보상을 지급하도록 처리합니다.
#import <ADXLibrary/ADXGdprManager.h>
@import GoogleMobileAds;
@interface AdMobRewardViewController () <GADFullScreenContentDelegate>
@property (nonatomic, strong) GADRewardedAd *rewardedAd;
@end
@implementation AdMobRewardViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self createAndLoadRewardedAd];
}
- (void)createAndLoadRewardedAd {
GADRequest *request = [GADRequest request];
//*** GDPR
if ([ADXGdprManager sharedInstance].consentState == ADXConsentStateDenied) {
GADExtras *extras = [[GADExtras alloc] init];
extras.additionalParameters = @{@"npa": @"1"};
[request registerAdNetworkExtras:extras];
}
[GADRewardedAd loadWithAdUnitID:@"<ADMOB_REWARD_AD_UNIT_ID>" request:request completionHandler:^(GADRewardedAd *rewardedAd, NSError *error) {
if (error) {
// Handle ad failed to load case.
} else {
// Ad successfully loaded.
self.rewardedAd = rewardedAd;
self.rewardedAd.fullScreenContentDelegate = self;
}
}];
}
- (IBAction)selectShowAd:(id)sender {
if (self.rewardedAd) {
[self.rewardedAd presentFromRootViewController:self userDidEarnRewardHandler:^{
GADAdReward *reward = self.rewardedAd.adReward;
// TODO: Reward the uesr!
}];
} else {
NSLog(@"Ad wasn't ready");
[self createAndLoadRewardedAd];
}
}
#pragma mark - GADFullScreenContentDelegate
- (void)adDidDismissFullScreenContent:(id<GADFullScreenPresentingAd>)ad {
[self createAndLoadRewardedAd];
}
@end
3. Callback
GADFullScreenContentDelegate
를 설정하여 특정 이벤트를 수신할 수 있습니다. 필요에 따라 구현해주세요.
#pragma mark - GADFullScreenContentDelegate
/// Tells the delegate that an impression has been recorded for the ad.
- (void)adDidRecordImpression:(id<GADFullScreenPresentingAd>)ad;
/// Tells the delegate that the ad failed to present full screen content.
- (void)ad:(id<GADFullScreenPresentingAd>)ad didFailToPresentFullScreenContentWithError:(NSError *)error;
/// Tells the delegate that the ad presented full screen content.
- (void)adDidPresentFullScreenContent:(id<GADFullScreenPresentingAd>)ad;
/// Tells the delegate that the ad dismissed full screen content.
- (void)adDidDismissFullScreenContent:(id<GADFullScreenPresentingAd>)ad;
4. 테스트 기기 등록
개발 중 상용 광고 키로 광고를 테스트하려는 경우 아래 단계에 따라 테스트 기기를 등록 후 사용해주시기 바랍니다.
테스트 기기 미등록 상태로 테스트할 경우 계정이 정지될 수 있습니다.
1) ADXLibrary를 적용 후 광고를 로드하는 코드가 삽입된 상태로 실행해주시면 콘솔에서 해당 로그를 확인하실 수 있습니다.
<Google> To get test ads on this device, set:
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ @"aa20271272d6558e1bff61b329dd436c" ];
2) 출력된 Device ID를 복사하여 아래와 같이 testDeviceIdentifiers
를 통해 테스트 기기를 등록해주시면 됩니다.
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ @"aa2027
Last updated
Was this helpful?