How can custom Ads be displayed?
To add your own Ads to the content of a Liveblog you have to implement two things. An AdProvider T2AdProvider
intended to manage the reuse and loading of Advertisments during scrolling and an AdView T2AdView
to display the Advertisments in the content. You have to register the AdProvider to the TickarooSDK by calling [TickarooSDK registerProvider: forAdType:]
T2AdProvider
The AdProvider needs to implement the following method, which is the entry-point for loading Advertisments when they are appearing on screen.
- (void)loadAdViewForRow:(TApiAdRow *)row
ad:(TApiAbstractAd *)ad
completion:(void (^)(UIView<T2AdView> *))completion;
Parameters
row
The row object; typeTApiAdRow
ad
The ad object for which the adprovider is registered; typeTApiAbstractAd
completion
Block to be called when loading the AdView is finished. Here you provide the UIView to display.
Example code for an AdProvider registerd for Ads of type TApiCustomerFrameworkAd
- (void)loadAdViewForRow:(TApiAdRow *)row ad:(TApiAbstractAd *)ad completion:(void (^)(UIView<T2AdView> *))completion {
TApiCustomerFrameworkAd *myAd = nil;
if ([ad isKindOfClass:[TApiCustomerFrameworkAd class]]) {
myAd = (TApiCustomerFrameworkAd *)ad;
}
if (myAd) {
@synchronized (myAd) {
if (myAd.adView && myAd.adView.isLoaded) {
completion(myAd.adView);
} else {
HTMLAdView *adView = [[HTMLAdView alloc] initWithAd:myAd];
myAd.adView = adView;
adView.loadCompletionCallback = completion;
[adView load];
}
}
} else {
completion(nil);
}
}
T2AdView
For displaying an Advertisment in the content you have to provide an UIView
which implements the T2AdView
protocol:
@protocol T2AdView <NSObject>
@property (nonatomic, copy) void(^didChangeHeight)();
@property (nonatomic, getter=isLoaded) BOOL loaded;
@property (nonatomic, strong) TApiAbstractAd *ad;
- (CGFloat)heightForWidth:(CGFloat)width;
@end
Properties
didChangeHeight
This block will be assigned by theTickarooSDK
and should be called everytime the AdView wants to resize its content. You not call the block on intermediate size changes as this will annoy the user.loaded
Tells either or not the content is completly loadedad
Should return theTApiAbstractAd
instance the AdView presents.
Methods
- (CGFloat)heightForWidth:(CGFloat)width
Here you have to return the height the AdView wants for a specific width
You can find an example implementation for an AdView displaying HTML-Ads from googlesyndication.com and one displaying simple Image-Ads in our Embed-Demo