All Products
Search
Document Center

Mobile Platform as a Service:Configure preset booth

Last Updated:Aug 03, 2021

To preset a booth on an iOS page, you need to perform two operations: data access and UI access. Data access callback obtains booth data. UI access obtains UI objects generated based on booth data.

If you are a beginner, we recommend that you configure the advertisement booths of iOS pages dynamically on the server-side mPaaS console. For details, refer to Create a booth.

Note: The access object in booth preset is usually a subclass of ViewController, and must implement the PromotionCenterDelegate method.

UI access procedure

  1. Add protocol implementation.
    The ViewController object implements the delivery protocolPromotionCenterDelegate.
    1. @interface DemoViewController () <CDPPromotionCenterDelegate>
    2. @end
  2. Add delivery listener.
    Call the added listener operation in or before the viewDidLoad of the ViewController. When the delivery data is ready, the API will be called back through the protocol method.
    1. NSArray *spaceCodes = @[@"code1", @"code2"];
    2. [CDPPromotionCenter addObserver:self
    3. spaceCodesForView:spaceCodes
    4. spaceCodesForData:nil
    5. extInfo:nil
    6. immediately:YES];
  3. Implement the callback method of the spaceView object in the PromotionCenterDelegate protocol to add the generated view to the page.
    1. - (void)promotionViewDidFinishLoading:(CDPSpaceView *)spaceView
    2. spaceCode:(NSString *)spaceCode {
    3. // Add the obtained spaceView to the screen.
    4. // If the returned spaceView is nil, which indicates a request for deleting the ad, you must delete the ad content. Then the page resumes to the state without ads.
  4. Remove the listener.
    Remove the listener upon page closing. You can remove the listener in the dealloc method of ViewController.
    1. - (void)dealloc {
    2. [CDPPromotionCenter removeObserver:self];
    3. }

Data access procedures

  1. Add protocol implementation.
    The ViewController object implements the delivery protocolPromotionCenterDelegate.
    1. @interface DemoViewController () <CDPPromotionCenterDelegate>
    2. @end
  2. Add delivery listener.
    Call the added listener operation in or before the viewDidLoad of the ViewController. When the delivery data is ready, the API will be called back through the protocol method.
    1. NSArray *spaceCodes = @[@"code1", @"code2"];
    2. [CDPPromotionCenter addObserver:self
    3. spaceCodesForView:nil
    4. spaceCodesForData:spaceCodes
    5. extInfo:nil
    6. immediately:YES];
  3. Implement the callback method of the spaceInfo object in the PromotionCenterDelegate protocol and perform custom processing based on the returned data.

    1. - (void)promotionDataDidFinishLoading:(CDPSpaceInfo *)spaceInfo
    2. spaceCode:(NSString *)spaceCode {
    3. // Generates the advertisement view to be displayed based on spaceInfo.
    4. // Customizes the view or uses the CDPSpaceView class provided by the SDK.
    5. // Adds the advertisement view to the screen.
    6. }
  4. Remove the listener.
    Remove the listener upon page closing. You can remove the listener in the dealloc method of ViewController.
    1. - (void)dealloc {
    2. [CDPPromotionCenter removeObserver:self];
    3. }