Configure preset ad spaces

更新时间:
复制 MD 格式

Configuring preset ad spaces on an iOS page involves two parts: data ingestion and UI integration. The data ingestion callback retrieves ad space data. The UI integration retrieves UI objects that are generated from the ad space data.

If you are new to the smart delivery component, you can configure the iOS page for the ad space dynamically through the component's console (server-side). For more information about server-side configurations, see Create an ad space.

Note

The object for preset integration is typically a child class of ViewController. This object must implement the PromotionCenterDelegate method.

UI integration

  1. Implement the protocol. The ViewController object implements the PromotionCenterDelegate protocol.

     @interface DemoViewController () <CDPPromotionCenterDelegate>
     @end
  2. Add a delivery listener.

    Call the add listener method in the viewDidLoad method of ViewController or earlier. When the delivery data is ready, a callback is invoked through the protocol method.

     NSArray *spaceCodes = @[@"code1", @"code2"];
     [CDPPromotionCenter addObserver:self
                            spaceCodesForView:spaceCodes
                            spaceCodesForData:nil
                                            extInfo:nil
                                     immediately:YES];
  3. Implement the callback method for the spaceView object in the PromotionCenterDelegate protocol. Add the generated view to the page.

     - (void)promotionViewDidFinishLoading:(CDPSpaceView *)spaceView
                                           spaceCode:(NSString *)spaceCode {
         // Add the retrieved spaceView to the screen.
         // If the returned spaceView is nil, it indicates a request to delete the ad. Delete the ad content and restore the page to its state without the ad.
  4. Remove the listener.

    Remove the listener in the dealloc method of ViewController when the page is closed.

     - (void)dealloc {
         [CDPPromotionCenter removeObserver:self];
     }

Data ingestion

  1. Implement the protocol. The ViewController object implements the PromotionCenterDelegate protocol.

     @interface DemoViewController () <CDPPromotionCenterDelegate>
     @end
  2. Add a delivery listener.

    Call the add listener method in the viewDidLoad method of ViewController or earlier. When the delivery data is ready, a callback is invoked through the protocol method.

     NSArray *spaceCodes = @[@"code1", @"code2"];
     [CDPPromotionCenter addObserver:self
                            spaceCodesForView:nil
                            spaceCodesForData:spaceCodes
                                            extInfo:nil
                                     immediately:YES];
  3. Implement the callback method for the spaceInfo object in the PromotionCenterDelegate protocol. Process the returned data as needed.

     - (void)promotionDataDidFinishLoading:(CDPSpaceInfo *)spaceInfo 
                             spaceCode:(NSString *)spaceCode {
         // Generate the ad view to be displayed based on spaceInfo.
       // Generate the view yourself or use the CDPSpaceView class provided by the SDK.
       // Add the ad view to the screen.
    
     }
  4. Remove the listener.

    Remove the listener in the dealloc method of ViewController when the page is closed.

     - (void)dealloc {
         [CDPPromotionCenter removeObserver:self];
     }