Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom targeting prop on iOS #177

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion RNPublisherBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default class PublisherBanner extends React.Component {
}

render() {
const { adUnitID, testDeviceID, bannerSize, style, didFailToReceiveAdWithError,admobDispatchAppEvent } = this.props;
const { adUnitID, testDeviceID, bannerSize, style, didFailToReceiveAdWithError,admobDispatchAppEvent, customTargeting } = this.props;

return (
<View style={this.props.style}>
<RNBanner
Expand All @@ -39,6 +40,7 @@ export default class PublisherBanner extends React.Component {
onAdmobDispatchAppEvent={(event) => admobDispatchAppEvent(event)}
testDeviceID={testDeviceID}
adUnitID={adUnitID}
customTargeting={customTargeting}
bannerSize={bannerSize} />
</View>
);
Expand Down Expand Up @@ -73,6 +75,10 @@ PublisherBanner.propTypes = {
*/
testDeviceID: React.PropTypes.string,

/**
* Custom targeting for DFP Banners
*/
customTargeting: React.PropTypes.object,
/**
* AdMob iOS library events
*/
Expand Down
1 change: 1 addition & 0 deletions ios/RNAdMobDFPManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ - (dispatch_queue_t)methodQueue
RCT_EXPORT_VIEW_PROPERTY(bannerSize, NSString);
RCT_EXPORT_VIEW_PROPERTY(adUnitID, NSString);
RCT_EXPORT_VIEW_PROPERTY(testDeviceID, NSString);
RCT_EXPORT_VIEW_PROPERTY(customTargeting, NSDictionary);

RCT_EXPORT_VIEW_PROPERTY(onSizeChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onAdmobDispatchAppEvent, RCTBubblingEventBlock)
Expand Down
1 change: 1 addition & 0 deletions ios/RNDFPBannerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@property (nonatomic, copy) NSString *bannerSize;
@property (nonatomic, copy) NSString *adUnitID;
@property (nonatomic, copy) NSString *testDeviceID;
@property (nonatomic, copy) NSDictionary *customTargeting;

@property (nonatomic, copy) RCTBubblingEventBlock onSizeChange;
@property (nonatomic, copy) RCTBubblingEventBlock onAdmobDispatchAppEvent;
Expand Down
18 changes: 17 additions & 1 deletion ios/RNDFPBannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ -(void)loadBanner {
_bannerView.delegate = self;
_bannerView.adUnitID = _adUnitID;
_bannerView.rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
GADRequest *request = [GADRequest request];
DFPRequest *request = [DFPRequest request];

if (_customTargeting) {
request.customTargeting = _customTargeting;
}

if(_testDeviceID) {
if([_testDeviceID isEqualToString:@"EMULATOR"]) {
request.testDevices = @[kGADSimulatorID];
Expand Down Expand Up @@ -122,6 +127,17 @@ - (void)setTestDeviceID:(NSString *)testDeviceID
}
}

- (void)setCustomTargeting:(NSDictionary *)customTargeting
{
if(![customTargeting isEqual:_customTargeting]) {
_customTargeting = customTargeting;
if (_bannerView) {
[_bannerView removeFromSuperview];
}
[self loadBanner];
}
}

-(void)layoutSubviews
{
[super layoutSubviews ];
Expand Down