PIP 모드 지원
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
iOS용 미디어 광고 (IMA) SDK
이 가이드는 기존 IMA 구현에 PIP 지원을 추가하려는 IMA 게시자를 위해 작성되었습니다.
기본 요건
앱에 PIP 모드 지원 추가
SDK 버전 3.1.0부터 IMA는 iPad용 Apple의 PIP 모드를 지원합니다.
앱에 PIP 지원을 추가하려면 아래와 같이 몇 가지 설정을 조정하고 몇 가지 새로운 IMA 클래스를 구현해야 합니다.
백그라운드 재생을 허용하도록 설정 업데이트
PIP 모드를 사용하려면 앱에서 백그라운드 미디어 재생을 허용해야 합니다.
아래와 같이 오디오, AirPlay, PIP 모드의 백그라운드 모드를 ON으로 설정합니다.

AVAudioSession
속성을 설정하여 백그라운드 재생을 지원하고 IMASettings
에서 백그라운드 재생을 사용 설정합니다.
...
– (void)viewDidLoad {
[super viewDidLoad];
self.playButton.layer.zPosition = MAXFLOAT;
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[self setupAdsLoader];
[self setUpContentPlayer];
}
– (void)setupAdsLoader {
IMASettings *settings = [[IMASettings alloc] init];
settings.enableBackgroundPlayback = YES;
self.adsLoader = [[IMAAdsLoader alloc] initWithSettings:settings];
self.adsLoader.delegate = self;
}
PIP 모드를 위한 새 iOS 및 IMA 객체 만들기
PIP를 지원하기 위해 Apple은 AVPictureInPictureController
및 AVPictureinPictureControllerDelegate
클래스를 추가했습니다. IMA는 IMAPictureInPictureProxy
를 추가했습니다. 프로젝트에 이러한 클래스를 통합하려면 코드에 다음 문을 추가하세요.
...
@interface VideoViewController () <AVPictureInPictureControllerDelegate,
IMAAdsLoaderDelegate,
IMAAdsManagerDelegate,
UIAlertViewDelegate>
...
// PiP objects.
@property(nonatomic, strong) IMAPictureInPictureProxy *pictureInPictureProxy;
@property(nonatomic, strong) AVPictureInPictureController *pictureInPictureController;
...
@end
- (void)setUpContentPlayer {
...
self.pictureInPictureProxy =
[[IMAPictureInPictureProxy alloc] initWithAVPictureInPictureControllerDelegate:self];
self.pictureInPictureController =
[[AVPictureInPictureController alloc] initWithPlayerLayer:self.contentPlayerLayer];
self.pictureInPictureController.delegate = self.pictureInPictureProxy;
}
광고 요청 수정
IMAAVPlayerVideoDisplay
라는 새 객체를 하나 더 만들어야 합니다. 이는 IMAAdsRequest
생성자에 전달되며, 동영상이 PIP 모드로 재생될 때 SDK가 PIP 창에 광고를 삽입할 수 있도록 합니다.
...
- (void)requestAdsWithTag:(NSString *)adTagUrl {
[self logMessage:@"Requesting ads"];
// Create an ad request with our ad tag, display container, and optional user context.
IMAAdsRequest *request = [[IMAAdsRequest alloc]
initWithAdTagUrl:adTagUrl
adDisplayContainer:[self createAdDisplayContainer]
avPlayerVideoDisplay:[[IMAAVPlayerVideoDisplay alloc] initWithAVPlayer:self.contentPlayer]
pictureInPictureProxy:self.pictureInPictureProxy
userContext:nil];
[self.adsLoader requestAdsWithRequest:request];
}
광고 시작
IMA SDK 광고는 PIP 모드에서 시작할 수 없습니다. 따라서 동영상이 표준 재생 모드에 있을 때만 [adsManager start]
를 호출해야 합니다.
...
- (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdEvent:(IMAAdEvent *)event {
[self logMessage:@"AdsManager event (%s).", AdEventNames[event.type]];
// When the SDK notified you that ads have been loaded, play them.
switch (event.type) {
case kIMAAdEvent_LOADED:
if (![self.pictureInPictureController isPictureInPictureActive]) {
[adsManager start];
}
break;
...
default:
break;
}
}
PIP 모드로 들어가기
AVPlayerViewController
없이 AVPlayer
를 사용하는 경우 자체 PIP 버튼을 추가해야 합니다. 고급 샘플에서 다음과 같이 구현했습니다.
- (IBAction)onPipButtonClicked:(id)sender {
if ([self.pictureInPictureController isPictureInPictureActive]) {
[self.pictureInPictureController stopPictureInPicture];
} else {
[self.pictureInPictureController startPictureInPicture];
}
}
FAQ
- 동영상이 PIP 모드일 때 광고를 시작하려면 어떻게 해야 하나요?
- 동영상이 PIP 모드일 때는 광고를 시작할 수 없습니다. 광고는 일반 재생 모드에서만 시작할 수 있습니다.
- 기존 PIP 통합에서
self.pictureInPictureController.delegate
를 자체 클래스로 설정해야 합니다. PIP에서 IMA 광고를 구현하면서도 대리인이 되려면 어떻게 해야 하나요?
- IMA SDK는 PIP 모드에서 광고 재생을 사용 설정하기 위해
AVPictureinPictureControllerDelegate
메시지도 수신해야 합니다. 이러한 이유로 AVPictureinPictureController
의 대리자를 IMAPictureInPicturyProxy
인스턴스로 설정해야 합니다. 이 프록시 객체는 모든 AVPictureinPictureControllerDelegate
메시지를 앱에 전달할 뿐만 아니라 PIP 모드 지원을 사용 설정하기 위해 IMA에 대한 호출도 전달합니다. AVPlayerLayer에 대한 로컬 핸들도 유지해야 합니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eThis guide explains how to add Picture-in-Picture support to your iOS app using the IMA SDK, version 3.1.0 and later.\u003c/p\u003e\n"],["\u003cp\u003eTo enable Picture-in-Picture, you must allow background media playback in your app settings and implement specific IMA and iOS classes like \u003ccode\u003eIMAPictureInPictureProxy\u003c/code\u003e and \u003ccode\u003eAVPictureInPictureController\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe IMA SDK requires the use of \u003ccode\u003eIMAAVPlayerVideoDisplay\u003c/code\u003e for ad insertion within the Picture-in-Picture window and ads can only be started in standard playback mode, not during Picture-in-Picture.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers might need to adjust their ad request and utilize the provided proxy object to manage \u003ccode\u003eAVPictureinPictureControllerDelegate\u003c/code\u003e messages effectively for ad playback and Picture-in-Picture support.\u003c/p\u003e\n"]]],[],null,["# Support Picture in Picture\n\nMedia Ads (IMA) SDK for iOS.\n\n\u003cbr /\u003e\n\nThis guide is intended for IMA publishers who want to add Picture in\nPicture support to their existing IMA implementation.\n\nPrerequisites\n-------------\n\n- Complete the [Get Started\n guide](/interactive-media-ads/docs/sdks/ios/client-side).\n\nAdding picture-in-picture support to your app\n---------------------------------------------\n\nAs of SDK version 3.1.0, IMA supports Apple's Picture in Picture mode for iPad.\nTo add support for Picture in Picture to your app, you need to tweak a few\nsettings and implement a few new IMA classes, as shown below.\n\n### Updating settings to allow background playback\n\nPicture in Picture mode requires that you allow background media playback in\nyour app.\n\n1. Set **Background Modes** to **ON** for **Audio, AirPlay and Picture in\n Picture** as shown below:\n\n2. Set the `AVAudioSession` properties to support background playback, as well\n as enable background playback in `IMASettings`:\n\n ```objective-c\n ...\n – (void)viewDidLoad {\n [super viewDidLoad];\n\n self.playButton.layer.zPosition = MAXFLOAT;\n\n [[AVAudioSession sharedInstance] setActive:YES error:nil];\n [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];\n\n [self setupAdsLoader];\n [self setUpContentPlayer];\n }\n\n – (void)setupAdsLoader {\n IMASettings *settings = [[IMASettings alloc] init];\n settings.enableBackgroundPlayback = YES;\n self.adsLoader = [[IMAAdsLoader alloc] initWithSettings:settings];\n self.adsLoader.delegate = self;\n }\n ```\n\n### Creating new iOS and IMA objects for picture-in-picture\n\nTo support Picture in Picture, Apple added the `AVPictureInPictureController`\nand `AVPictureinPictureControllerDelegate` classes. IMA, for its part, added\n`IMAPictureInPictureProxy`. To incorporate these classes in your project, add\nthe following statements to your code: \n\n```objective-c\n...\n@interface VideoViewController () \u003cAVPictureInPictureControllerDelegate,\n IMAAdsLoaderDelegate,\n IMAAdsManagerDelegate,\n UIAlertViewDelegate\u003e\n...\n// PiP objects.\n@property(nonatomic, strong) IMAPictureInPictureProxy *pictureInPictureProxy;\n@property(nonatomic, strong) AVPictureInPictureController *pictureInPictureController;\n...\n@end\n\n- (void)setUpContentPlayer {\n ...\n self.pictureInPictureProxy =\n [[IMAPictureInPictureProxy alloc] initWithAVPictureInPictureControllerDelegate:self];\n self.pictureInPictureController =\n [[AVPictureInPictureController alloc] initWithPlayerLayer:self.contentPlayerLayer];\n self.pictureInPictureController.delegate = self.pictureInPictureProxy;\n}\n```\n\n### Modifying your ads request\n\nThere's one more new object to create: `IMAAVPlayerVideoDisplay`. This is passed\nto your `IMAAdsRequest` constructor and allows the SDK to insert ads into the PiP\nwindow when your video is playing in Picture in Picture mode: \n\n```objective-c\n...\n- (void)requestAdsWithTag:(NSString *)adTagUrl {\n [self logMessage:@\"Requesting ads\"];\n // Create an ad request with our ad tag, display container, and optional user context.\n IMAAdsRequest *request = [[IMAAdsRequest alloc]\n initWithAdTagUrl:adTagUrl\n adDisplayContainer:[self createAdDisplayContainer]\n avPlayerVideoDisplay:[[IMAAVPlayerVideoDisplay alloc] initWithAVPlayer:self.contentPlayer]\n pictureInPictureProxy:self.pictureInPictureProxy\n userContext:nil];\n [self.adsLoader requestAdsWithRequest:request];\n}\n```\n\n### Starting ads\n\nIMA SDK ads **cannot be started during picture in picture mode** . As a result,\nyou need to ensure that you only call `[adsManager start]` when your video is in\nstandard playback mode: \n\n```objective-c\n...\n- (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdEvent:(IMAAdEvent *)event {\n [self logMessage:@\"AdsManager event (%s).\", AdEventNames[event.type]];\n // When the SDK notified you that ads have been loaded, play them.\n switch (event.type) {\n case kIMAAdEvent_LOADED:\n if (![self.pictureInPictureController isPictureInPictureActive]) {\n [adsManager start];\n }\n break;\n ...\n default:\n break;\n }\n}\n```\n\n### Entering picture-in-picture mode\n\nIf you're using an `AVPlayer` without an `AVPlayerViewController`, you need to\nadd your own Picture in Picture button. We've implemented one in our [Advanced\nSample](//github.com/googleads/googleads-ima-ios/tree/master/Objective-C/AdvancedExample)\nlike this: \n\n - (IBAction)onPipButtonClicked:(id)sender {\n if ([self.pictureInPictureController isPictureInPictureActive]) {\n [self.pictureInPictureController stopPictureInPicture];\n } else {\n [self.pictureInPictureController startPictureInPicture];\n }\n }\n\nFAQ\n---\n\nHow do I start ads when the video is in Picture in Picture mode?\n: Ads cannot be started while the video is in Picture in Picture mode; they\n can only be started in standard playback mode.\n\nMy existing Picture in Picture integration needs to set `self.pictureInPictureController.delegate` to my own class. How can I implement IMA ads in Picture in Picture and still be the delegate?\n: The IMA SDK also needs to receive `AVPictureinPictureControllerDelegate`\n messages to enable ad playback in Picture in Picture mode. This is why we ask\n you to set the delegate for `AVPictureinPictureController` to an instance of\n `IMAPictureInPicturyProxy`. This proxy object forwards on all\n `AVPictureinPictureControllerDelegate` messages to your app, but also forwards\n the calls to IMA to enable Picture in Picture support. Note that you must also\n maintain a local handle to your AVPlayerLayer."]]