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.
The object for preset integration is typically a child class of ViewController. This object must implement the PromotionCenterDelegate method.
UI integration
Implement the protocol. The
ViewControllerobject implements thePromotionCenterDelegateprotocol.@interface DemoViewController () <CDPPromotionCenterDelegate> @endAdd a delivery listener.
Call the add listener method in the
viewDidLoadmethod ofViewControlleror 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];Implement the callback method for the
spaceViewobject in thePromotionCenterDelegateprotocol. Add the generatedviewto 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.Remove the listener.
Remove the listener in the
deallocmethod ofViewControllerwhen the page is closed.- (void)dealloc { [CDPPromotionCenter removeObserver:self]; }
Data ingestion
Implement the protocol. The
ViewControllerobject implements thePromotionCenterDelegateprotocol.@interface DemoViewController () <CDPPromotionCenterDelegate> @endAdd a delivery listener.
Call the add listener method in the
viewDidLoadmethod ofViewControlleror 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];Implement the callback method for the
spaceInfoobject in thePromotionCenterDelegateprotocol. 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. }Remove the listener.
Remove the listener in the
deallocmethod ofViewControllerwhen the page is closed.- (void)dealloc { [CDPPromotionCenter removeObserver:self]; }