iOS 13부터 애플리케이션은 iPad에서 멀티 윈도우를 지원할 수 있습니다. 즉, 사용자는 앱 UI의 여러 사본과 동시에 상호작용할 수 있습니다. 각 창은 다양한 크기로 만들 수 있고 언제든지 크기를 조절할 수 있으므로 광고가 로드되고 표시되는 방식에 영향을 미칩니다.
본 가이드에는 iPad 멀티 윈도우 시나리오에서 광고를 올바르게 렌더링하기 위한 권장사항이 나와 있습니다.
기본 요건
- Google 모바일 광고 SDK 7.53.0 이상
- 프로젝트에서 장면 지원 사용 설정
- 광고 형식을 하나 이상 구현
광고 요청에서 장면 설정
특정 창에 맞는 광고를 수신하려면 뷰의 windowScene
를
광고 요청에 전달합니다. Google 모바일 광고 SDK는 장면에 적합한
크기의 광고를 반환합니다.
Swift
func loadInterstitial() { let request = GADRequest() request.scene = view.window?.windowScene GADInterstitialAd.load(withAdUnitID: "[AD_UNIT_ID]", request: request) { ad, error in } }
Objective-C
- (void)loadInterstitial { GADRequest *request = [GADRequest request]; request.scene = self.view.window.windowScene; [GADInterstitialAd loadWithAdUnitID:@"[AD_UNIT_ID]" request:request completionHandler:^(GADInterstitialAd *ad, NSError *error) {}]; }
테스트 모드에서 멀티 장면 앱이 장면을 전달하지 않고 광고를 요청하면 광고 요청이 실패하고 다음 오류가 표시됩니다.
<Google> Invalid Request. The GADRequest scene property should be set for
applications that support multi-scene. Treating the unset property as an error
while in test mode.
프로덕션 모드에서는 광고 요청이 처리되지만, 광고가 전체 화면이 아닌 창에 표시되는 경우 광고 표시가 실패합니다. 이 경우 오류 메시지는 다음과 같습니다.
<Google> Ad cannot be presented. The full screen ad content size exceeds the current window size.
viewDidAppear에서 광고 요청을 작성합니다.
멀티 윈도우의 경우 광고 요청을 전송하기 위한 창 장면이 있어야 합니다. 아직 viewDidLoad:
의 창에 뷰가 추가되지 않았으므로
이 지점까지 창 장면이 설정되는
viewDidAppear:
에서 광고 요청을 작성해야 합니다.
viewDidAppear:
는 앱의 수명 주기 동안 두 번 이상 호출될 수 있습니다. 광고 요청 초기화 코드는 이미 완료되었는지 여부를 나타내는 플래그 안에
넣는 것이 좋습니다.
Swift
override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) if !requestInitialized { loadInterstitial() requestInitialized = true } }
Objective-C
- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (!_requestInitialized) { [self loadInterstitial]; _requestInitialized = YES; } }
크기 조절 처리
사용자는 언제든지 장면을 드래그하여 광고 요청이 이루어진 후 창 크기를 변경할 수 있습니다. 크기가 조절될 때 새 광고를 요청할지 여부는 게시자가 결정합니다.
아래 샘플 코드에서는 viewWillTransitionToSize:withTransitionCoordinator:
를 사용하여 루트 뷰 컨트롤러의 창이 회전하거나 크기가 조절될 때 알림을 받지만, 창 장면별 변경에 관한 windowScene:didUpdateCoordinateSpace:interfaceOrientation:traitCollection:
를 수신 대기할 수도 있습니다.
전면 광고 및 보상형 광고
Google 모바일 광고 SDK에서는
canPresentFromViewController:error:
메서드를 제공하여 전면 광고 또는 보상형 광고의
유효성을 판단하고, 창 크기가 변경될 때마다 전체 화면 광고를
새로고침해야 하는지 여부를 확인할 수 있습니다.
Swift
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) coordinator.animate(alongsideTransition: nil) { [self] context in do { try interstitial?.canPresent(fromRootViewController: self) } catch { loadInterstitial() } } }
Objective-C
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [coordinator animateAlongsideTransition:nil completion:^(id _Nonnull context) { if (![self.interstitial canPresentFromRootViewController:self error:nil]) { [self loadInterstitial]; } }]; }
배너
창 회전과 동일한 방식으로 창 크기 조절을 처리할 수 있습니다. 앱은 배너 광고가 새 창 크기에 맞도록 해야 합니다.
아래 예에서는 새 창 너비로 새 적응형 배너를 만듭니다.
Swift
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) coordinator.animate(alongsideTransition: nil) { [self] context in loadBanner() } } func loadBanner() { let bannerWidth = view.frame.size.width bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(bannerWidth) let request = GADRequest() request.scene = view.window?.windowScene bannerView.load(request) }
Objective-C
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [coordinator animateAlongsideTransition:nil completion:^(id _Nonnull context) { [self loadBannerAd]; }]; } - (void)loadBannerAd { CGFloat bannerWidth = self.view.frame.size.width; self.bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(bannerWidth); GADRequest *request = [GADRequest request]; request.scene = self.view.window.windowScene; [self.bannerView loadRequest:request]; }
네이티브 광고
네이티브 광고 렌더링을 직접 관리할 수 있으며, 앱의 나머지 부분과 마찬가지로 크기가 조정된 뷰 내에서 네이티브 광고가 렌더링되도록 할 책임이 있습니다.
알려진 문제
현재 멀티 윈도우 및 화면 분할 광고는 세로 모드에서만 지원됩니다. 가로 모드에서 광고를 요청하면 다음과 같은 로그 메시지가 표시됩니다.
<Google> Ad cannot be presented. The full screen ad content size exceeds the
current window size.