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.
To simplify the process of differentiating multiple ad managers, the IMA SDK for tvOS allows publishers to pass in any value or object to the UserContext field of any ad request. This value or object can then be retrieved in the AdsLoader:AdsLoadedWithData delegate function, via the IMAAdsLoadedData object's userContext attribute.
Example
...adsLoader=IMAAdsLoader(settings:nil)adsLoader.delegate=selfletuserContextA={id:"Request A",element:videoElementA}letuserContextB={id:"Request B",element:videoElementB}letrequestA=IMAAdsRequest(adTagUrl:ViewController.AdTagURLString,adDisplayContainer:adDisplayContainer,contentPlayhead:contentPlayhead,userContext:userContextA)letrequestB=IMAAdsRequest(adTagUrl:ViewController.AdTagURLString,adDisplayContainer:adDisplayContainer,contentPlayhead:contentPlayhead,userContext:userContextB)adsLoader.requestAds(with:requestA)adsLoader.requestAds(with:requestB)...//MARK:-IMAAdsLoaderDelegatefuncadsLoader(_loader:IMAAdsLoader!,adsLoadedWithadsLoadedData:IMAAdsLoadedData!){letuserContext=adsLoadedData.userContextprint("Loaded ads for ID: "+userContext.id)adsManager=adsLoadedData.adsManageradsManager.initialize(with:nil)}funcadsLoader(_loader:IMAAdsLoader!,failedWithadErrorData:IMAAdLoadingErrorData!){letuserContext=adsLoadingErrorData.userContextprint("Error loading ads for ID: "+userContext.id)}...
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-05 UTC."],[[["\u003cp\u003eThe IMA SDK for tvOS allows handling multiple concurrent ad requests by associating a unique context with each request.\u003c/p\u003e\n"],["\u003cp\u003ePublishers can provide a custom value or object using the \u003ccode\u003euserContext\u003c/code\u003e field during ad request creation.\u003c/p\u003e\n"],["\u003cp\u003eThis \u003ccode\u003euserContext\u003c/code\u003e can be retrieved in the \u003ccode\u003eadsLoader:adsLoadedWithData\u003c/code\u003e delegate method, enabling differentiation of responses.\u003c/p\u003e\n"],["\u003cp\u003eThis functionality simplifies managing ad responses in scenarios involving preloading ad data or simultaneous ad requests for different content.\u003c/p\u003e\n"]]],[],null,["Select platform: [HTML5](/interactive-media-ads/docs/sdks/html5/client-side/multiple-requests \"View this page for the HTML5 platform docs.\") [Android](/interactive-media-ads/docs/sdks/android/client-side/multiple-requests \"View this page for the Android platform docs.\") [iOS](/interactive-media-ads/docs/sdks/ios/client-side/multiple-requests \"View this page for the iOS platform docs.\") [tvOS](/interactive-media-ads/docs/sdks/tvos/client-side/multiple-requests \"View this page for the tvOS platform docs.\")\n\n\u003cbr /\u003e\n\nMost 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 tvOS 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 ..."]]