Skip to content

2.2 Aotter Ad Video 影音廣告 (deprecated)

superwave edited this page Aug 14, 2019 · 1 revision
  1. create adVideo object
  -(void)initialVideoAd{
     self.videoAd = [ATAdVideo alloc] init];
     //initial ad with place and categories(optional)
     [self.videoAd ATinitialWithPlace:@"<myAdPlace>"]:
      
     //set viewControllerForShowing to current ViewController
     [self.videoAd ATsetPresetingViewController:self];
 
     //set delegate (optional)
     self.videoAd.delegate = self;
      
     //fetch Ad data from API
     [self.videoAd ATfetchAd:^(NSDictionary *adData) {
         dispatch_async(dispatch_get_main_queue(),^{
             //start to load playerItem. when finsished will receive delegate `ATAdVideoReadyToPlay:` and self.videoAd.isReadyToPlay == YES
         });
     }];
  }
   
  -(void)ATAdVideoReadyToPlay:(ATAdVideo *)ad{
    //rendering your VideoAd View or play the ad
  }
   
  1. render adNatvie UI object
  //set tracking view
  [self.videoAd ATsetTrackingView:self.myAdView];
  
  //set tracking Action button
  [self.videoAd ATsetTrackingActionButton:self.myButton];
  
  //set video conatiner view
  [self.videoAd ATsetVideoContainer:self.myVideoContainerView];

  //render adData
  NSDictionary adData = self.AdData;
  if(adData){
     //if fetchAd success, adData contains metadata for rendering
  }
  1. play and pause videoAd.

    devlopers have to handling the play/pause event by their own. for UITableView use tableView: willDisplayCell: and tableView: didEndDisplayingCell:.

       //play
       [self.videoAd ATplayVideo];
       
       //pause
       [self.videoAd ATpauseVideo];

adData

Variable Type description
adType String
uuid String
title String
text String
sponser String
callToAction String for action button title
advertiserName String
img_icon String 82x82
img_icon_hd String 300x300
img_main String 1200x627
  1. other delegate
   @protocol ATAdVideoDelegate <NSObject>
   
   -(void)ATAdVideoReadyToPlay:(ATAdVideo *)ad;;
   -(void)ATAdVideoDidReceiveAd:(ATAdVideo *)ad;
   -(void)ATAdVideoFetchNoAd:(ATAdVideo *)ad;
   -(void)ATAdVideoDidDismissFullScreenMode:(ATAdVideo *)ad;
   
   @end
  1. show full screen player without inline native video ad
  //set transition style for fullscreen player
  [self.videoAd ATsetFullScreenPlayerTransition:UIModalTransitionStyleCrossDissolve]

  //set close button hide time (optional, default = 0) 
  [self.videoAd ATsetCloseButtonHideTime:3.0f];
  
  //show the fullscreen player
  [self.videoAd ATshowFullScreenPlayer];    
  1. fullscreen orientation

    ATAdVideo fullscreen player support responsive design. if your project is using UIInterfaceOrientationMask to handle orientation changing, detect ATAdVideoFullScreenViewController for presented.

        - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window{
         id presentedViewController = [window.rootViewController presentedViewController];
         NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;
         ATAdVideoFullScreenViewController *ATFullScreenVC = (ATAdVideoFullScreenViewController *)presentedViewController;
         
         if (window && [className isEqualToString:@"ATAdVideoFullScreenViewController"] && ATFullScreenVC.isPresented){
             return UIInterfaceOrientationMaskAll;
         }
         else {
             return UIInterfaceOrientationMaskPortrait;
         }
     }
  2. remove and release data

   //remove and release data
  [self.videoAd ATreleaseAd];