여러 광고 요청 처리
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
IMA SDK를 사용할 때는 한 번에 하나의 광고 요청만 관리하면 됩니다. 그러나 사용자가 동영상을 선택하기 전에 광고 데이터를 미리 로드하는 등의 일부 특수 사례 구현에서는 여러 개의 동시 요청을 해야 할 수 있습니다. 광고 요청은 비동기식으로 이루어지므로 적절한 광고 관리자가 올바른 컨텍스트와 연결되도록 하는 것이 쉽지 않아 보일 수 있습니다.
여러 광고 관리자를 구분하는 프로세스를 간소화하기 위해 iOS용 IMA SDK에서는 게시자가 광고 요청의 UserContext 필드에 값이나 객체를 전달할 수 있도록 허용합니다. 그런 다음 이 값 또는 객체는 IMAAdsLoadedData 객체의 userContext 속성을 통해 AdsLoader:AdsLoadedWithData 대리 함수에서 검색할 수 있습니다.
예
...
adsLoader = IMAAdsLoader(settings: nil)
adsLoader.delegate = self
let userContextA = {id: "Request A", element: videoElementA}
let userContextB = {id: "Request B", element: videoElementB}
let requestA = IMAAdsRequest(
adTagUrl: ViewController.AdTagURLString,
adDisplayContainer: adDisplayContainer,
contentPlayhead: contentPlayhead,
userContext: userContextA)
let requestB = IMAAdsRequest(
adTagUrl: ViewController.AdTagURLString,
adDisplayContainer: adDisplayContainer,
contentPlayhead: contentPlayhead,
userContext: userContextB)
adsLoader.requestAds(with: requestA)
adsLoader.requestAds(with: requestB)
...
// MARK: - IMAAdsLoaderDelegate
func adsLoader(_ loader: IMAAdsLoader!, adsLoadedWith adsLoadedData: IMAAdsLoadedData!) {
let userContext = adsLoadedData.userContext
print("Loaded ads for ID: " + userContext.id)
adsManager = adsLoadedData.adsManager
adsManager.initialize(with: nil)
}
func adsLoader(_ loader: IMAAdsLoader!, failedWith adErrorData: IMAAdLoadingErrorData!) {
let userContext = adsLoadingErrorData.userContext
print("Error loading ads for ID: " + userContext.id)
}
...
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eThe IMA SDK for iOS allows publishers to manage multiple concurrent ad requests, especially useful for preloading ads.\u003c/p\u003e\n"],["\u003cp\u003ePublishers can utilize the \u003ccode\u003eUserContext\u003c/code\u003e field in \u003ccode\u003eIMAAdsRequest\u003c/code\u003e to associate a custom identifier with each ad request, simplifying differentiation.\u003c/p\u003e\n"],["\u003cp\u003eThe provided \u003ccode\u003euserContext\u003c/code\u003e value can be retrieved later in the \u003ccode\u003eadsLoader:adsLoadedWithData\u003c/code\u003e or \u003ccode\u003eadsLoader:failedWithAdErrorData\u003c/code\u003e delegate methods through the \u003ccode\u003eIMAAdsLoadedData\u003c/code\u003e or \u003ccode\u003eIMAAdLoadingErrorData\u003c/code\u003e object, respectively.\u003c/p\u003e\n"],["\u003cp\u003eThis approach helps ensure the correct ad manager is linked to its corresponding context, streamlining ad management in complex scenarios.\u003c/p\u003e\n"]]],[],null,["Most uses of the IMA SDK only require managing a single ad request at a time. However some edge case implementations, such as preloading ad data before the user selects a video, may require making multiple concurrent requests. Since ad requests are made asynchronously, ensuring the proper ad manager is associated with the correct context can seem to be a daunting task.\n\nTo simplify the process of differentiating multiple ad managers, the IMA SDK for iOS allows publishers to pass in any value or object to the [UserContext](https://developers.google.com/interactive-media-ads/docs/sdks/ios/client-side/reference/Classes/IMAAdsRequest#-initwithadtagurl:addisplaycontainer:avplayervideodisplay:pictureinpictureproxy:usercontext:) field of any ad request. This value or object can then be retrieved in the [AdsLoader:AdsLoadedWithData](https://developers.google.com/interactive-media-ads/docs/sdks/ios/client-side/reference/Protocols/IMAAdsLoaderDelegate#-adsloader:adsloadedwithdata:) delegate function, via the [IMAAdsLoadedData](https://developers.google.com/interactive-media-ads/docs/sdks/ios/client-side/reference/Classes/IMAAdsLoadedData) object's [userContext](https://developers.google.com/interactive-media-ads/docs/sdks/ios/client-side/reference/Classes/IMAAdsLoadedData#usercontext) attribute.\n\nExample \n\n ...\n adsLoader = IMAAdsLoader(settings: nil)\n adsLoader.delegate = self\n\n let userContextA = {id: \"Request A\", element: videoElementA}\n let userContextB = {id: \"Request B\", element: videoElementB}\n let requestA = IMAAdsRequest(\n adTagUrl: ViewController.AdTagURLString,\n adDisplayContainer: adDisplayContainer,\n contentPlayhead: contentPlayhead,\n userContext: userContextA)\n let requestB = IMAAdsRequest(\n adTagUrl: ViewController.AdTagURLString,\n adDisplayContainer: adDisplayContainer,\n contentPlayhead: contentPlayhead,\n userContext: userContextB)\n adsLoader.requestAds(with: requestA)\n adsLoader.requestAds(with: requestB)\n\n ...\n\n // MARK: - IMAAdsLoaderDelegate\n\n func adsLoader(_ loader: IMAAdsLoader!, adsLoadedWith adsLoadedData: IMAAdsLoadedData!) {\n let userContext = adsLoadedData.userContext\n print(\"Loaded ads for ID: \" + userContext.id)\n adsManager = adsLoadedData.adsManager\n adsManager.initialize(with: nil)\n }\n\n func adsLoader(_ loader: IMAAdsLoader!, failedWith adErrorData: IMAAdLoadingErrorData!) {\n let userContext = adsLoadingErrorData.userContext\n print(\"Error loading ads for ID: \" + userContext.id)\n }\n\n ..."]]