Display Banner Ads

The PSDK provides support for displaying banner ads.

To display banner ads:

  1. Create a new PTAdBannerView instance for each banner. For example:
    - (void) onMediaPlayerAdPlayStarted:(NSNotification *) notification {
        _currentAd  = [notification.userInfo  objectForKey:PTMediaPlayerAdKey]; 
        if (_currentAd != nil) {
            [self removeAllBanners]; // remove any existing PTAdBannerView views
    
            // banners
            if (_currentAd.companionAssets && _currentAd.companionAssets.count > 0) {
                PTAdAsset *bannerAsset = [_currentAd.companionAssets objectAtIndex:0];
    
                PTAdBannerView *bannerView = [[PTAdBannerView alloc] initWithAsset:bannerAsset]; 
                bannerView.player = self.player;
                bannerView.delegate = self;
    
                bannerView.frame = CGRectMake(0.0, 0.0, bannerAsset.width, bannerAsset.height); 
                [_adBannerView.bannerView addSubview:bannerView];
            }
        }
    }
  2. Add a listener for the PTMediaPlayerAdClickNotification notification. When an end user clicks a banner, the PSDK dispatches this notification, including information about the destination for the click.
  3. In your listener, use the information to display the appropriate destination URL, either by opening an internal Web page or by redirecting to an external browser, as shown:
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerAdClick:) 
      name:PTMediaPlayerAdClickNotification object:self.player];
    
    - (void) onMediaPlayerAdClick:(NSNotification *) notification {
        NSString *url = [notification.userInfo objectForKey:PTMediaPlayerAdClickURLKey]; 
        if (url != nil) {
            [self  openBrowser:[NSURL  URLWithString:url]];
        }
    }