This guide is intended for publishers interested in adding companion ads to their iOS IMA implementation.
- iOS Application with the IMA SDK integrated.
- An ad tag configured to return a companion ad.
- If you need a sample, check out our FAQ.
If you still need to implement the IMA SDK in your app, check out our Get Started guide.
Adding companion ads to your app
Create a UIView for your companion
Before requesting a companion, you need to create a space for it in our layout. In your storyboard, drag and drop a View onto your
ViewController and size it to your companion ad. Then, make sure your companion slot is tied to a variable in your implementation (we use a variable called companionView in this example). In the screenshot below, the light gray view is our companion ad view:
Create an IMACompanionAdSlot
The next step is to build an IMACompanionAdSlot object from your view:ViewController.h
@property(nonatomic, weak) IBOutlet UIView *companionView;ViewController.m
self.companionSlot = [[IMACompanionAdSlot alloc] initWithView:self.companionView width:self.companionView.frame.size.width height:self.companionView.frame.size.height];
Pass the companion ad slot to your ad container
Lastly, you'll need to let the SDK know that this companion slot exists by passing an array of your companion slots to the
return [[IMAAdDisplayContainer alloc] initWithAdContainer:self.videoView companionSlots:@[ self.companionSlot ]];
That's all there is to it! Your application is now displaying companion ads.
- I followed the guide, but I'm not seeing companion ads. What should I do?
- First, check to make sure your tag really is returning companions. To do this, open the tag in a web browser and look for a CompanionAds tag. If you see that, check to make sure the size of the companion being returned is the same size as the UIView in which you're trying to display it.