Reputation: 21
I'm trying to integrate HeyZap Native Ads Mediation into my UICollectionView. I'm using cells built with IB, but when I'm trying to assign nativeAd.wrapperView to my own wrapperView in cell it just do not response to any taps or gestures. Here is my code:
cell.hzNativeAd = ...; //Here I assign HZMediatedNativeAd to my cell property
cell.hzNativeAd.presentingViewController = self;
cell.hzNativeAd.shouldShowFacebookAdChoicesView = NO;
//Saving frame, because when I assign HeyZap wrapperView to my UIView frame is 0
CGRect wrapperViewFrame = cell.wrapperView.frame;
cell.wrapperView = cell.hzNativeAd.wrapperView;
cell.wrapperView.frame = wrapperViewFrame;
/*Assigning all labels and images
...
...
...
*/
//Registering Views with HZMediatedNativeAdViewRegisterer
[cell.hzNativeAd registerViews:^(id<HZMediatedNativeAdViewRegisterer>registerer) {
[registerer registerTitleView:cell.titleLabel tappable:YES];
[registerer registerBodyView:cell.descriptionLabel tappable:YES];
[registerer registerCallToActionView:cell.actionButton];
[registerer registerIconView:cell.imageView tappable:YES];
[registerer registerCoverImageView:cell.coverImageView tappable:YES];
From the HeyZap docs (https://developers.heyzap.com/docs/ios_sdk_native_mediation#step-3-show-native-ads) I can find how to do it programatically. But doing so gives me really bad results when testing on iPad. I'm creating views, than add constraints, then registering this views, then delete all of them when preparing for reuse - all of it takes time and I have lots of lags on iPad. HeyZap Support just do not reply...
So maybe someone faced this problem too... Or I'm just doing something wrong when assigning wrapperView this way?
Thanks for help!
Upvotes: 1
Views: 213
Reputation: 7707
I'm an iOS engineer with Heyzap. Let me start by apologizing for the complexity of the native ads integration—it's really hard to create a consistent interface between the ad networks, and since AdMob requires a wrapper view and registering views, it has to be at least that complex. Anyway, here's what I think are problems in your code:
This line: cell.wrapperView = cell.hzNativeAd.wrapperView;
won't work correctly. That's just taking the cell's wrapperView
pointer and changing what it points to, but it isn't changing the actual subview of the cell—you need to actually add the Heyzap wrapper view to the view hierarchy at some point for it to respond to gestures. Here's what I would do probably:
[cell.wrapperView removeFromSuperview]; // Temporarily remove your wrapper view from the view hierarchy, since when you load a new cell from a storyboard, it'll be a subview of the `contentView` property.
cell.hzNativeAd.wrapperView.frame = cell.wrapperView.frame;
[cell.contentView addSubview: cell.hzNativeAd.wrapperView];
[cell.hzNativeAd.wrapperView addSubview: cell.wrapperView];
(You may want to rename your wrapperView
property to something else to disambiguate it from Heyzap's).
As far as prepareForReuse
goes, you should be able to just do these things:
[self.wrapperView removeFromSuperview];
[cell.hzNativeAd.wrapperView removeFromSuperview];
nil
out your native ad reference: self.hzNativeAd = nil;
.[super prepareForReuse];
Sorry for the delayed response on this. It was Independence Day in America this past Monday, so most Heyzap employees were out of the office.
Tell me if you have any more questions; I can get on a Skype chat with you if necessary.
Upvotes: 0