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.
The access object in booth preset is usually a subclass of ViewController, and must implement the PromotionCenterDelegate method.
UI access procedure
Add protocol implementation.
The ViewControllerobject implements the delivery protocolPromotionCenterDelegate.@interface DemoViewController () <CDPPromotionCenterDelegate> @endAdd delivery listener.
Call the added listener operation in or before the
viewDidLoadof theViewController. When the delivery data is ready, the API will be called back through the protocol method.NSArray *spaceCodes = @[@"code1", @"code2"]; [CDPPromotionCenter addObserver:self spaceCodesForView:spaceCodes spaceCodesForData:nil extInfo:nil immediately:YES];Implement the callback method of the
spaceViewobject in thePromotionCenterDelegateprotocol to add the generatedviewto the page.- (void)promotionViewDidFinishLoading:(CDPSpaceView *)spaceView spaceCode:(NSString *)spaceCode { // Add the obtained spaceView to the screen. // 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.Remove the listener.
Remove the listener upon page closing. You can remove the listener in the
deallocmethod ofViewController.- (void)dealloc { [CDPPromotionCenter removeObserver:self]; }
Data access procedures
Add protocol implementation.
The ViewControllerobject implements the delivery protocolPromotionCenterDelegate.@interface DemoViewController () <CDPPromotionCenterDelegate> @endAdd delivery listener.
Call the added listener operation in or before the
viewDidLoadof theViewController. When the delivery data is ready, the API will be called back through the protocol method.NSArray *spaceCodes = @[@"code1", @"code2"]; [CDPPromotionCenter addObserver:self spaceCodesForView:nil spaceCodesForData:spaceCodes extInfo:nil immediately:YES];Implement the callback method of the
spaceInfoobject in thePromotionCenterDelegateprotocol and perform custom processing based on the returned data.- (void)promotionDataDidFinishLoading:(CDPSpaceInfo *)spaceInfo spaceCode:(NSString *)spaceCode { // Generates the advertisement view to be displayed based on spaceInfo. // Customizes the view or uses the CDPSpaceView class provided by the SDK. // Adds the advertisement view to the screen. }Remove the listener.
Remove the listener upon page closing. You can remove the listener in the
deallocmethod ofViewController.- (void)dealloc { [CDPPromotionCenter removeObserver:self]; }