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
- Add protocol implementation.
The ViewController
object implements the delivery protocolPromotionCenterDelegate
.@interface DemoViewController () <CDPPromotionCenterDelegate>
@end
- Add delivery listener.
Call the added listener operation in or before theviewDidLoad
of 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
spaceView
object in thePromotionCenterDelegate
protocol to add the generatedview
to 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 thedealloc
method ofViewController
.- (void)dealloc {
[CDPPromotionCenter removeObserver:self];
}
Data access procedures
- Add protocol implementation.
The ViewController
object implements the delivery protocolPromotionCenterDelegate
.@interface DemoViewController () <CDPPromotionCenterDelegate>
@end
- Add delivery listener.
Call the added listener operation in or before theviewDidLoad
of 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
spaceInfo
object in thePromotionCenterDelegate
protocol 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 thedealloc
method ofViewController
.- (void)dealloc {
[CDPPromotionCenter removeObserver:self];
}