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

fix: rewarded ads crash & request configuration #31

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions ios/RNGoogleAds/RNGoogleAdsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ - (void)setRequestConfiguration:(NSDictionary *)requestConfiguration {
}

if (requestConfiguration[@"tagForChildDirectedTreatment"]) {
BOOL tag = (BOOL)requestConfiguration[@"tagForChildDirectedTreatment"];
BOOL tag = [requestConfiguration[@"tagForChildDirectedTreatment"] boolValue];
[GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment:tag];
}

if (requestConfiguration[@"tagForUnderAgeOfConsent"]) {
BOOL tag = (BOOL)requestConfiguration[@"tagForUnderAgeOfConsent"];
BOOL tag = [requestConfiguration[@"tagForUnderAgeOfConsent"] boolValue];
[GADMobileAds.sharedInstance.requestConfiguration tagForUnderAgeOfConsent:tag];
}

Expand Down
22 changes: 14 additions & 8 deletions ios/RNGoogleAds/RNGoogleAdsRewardedModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ - (void)invalidate {
rewardedMap[requestId] = rewardedAd;
rewardedDelegateMap[requestId] = fullScreenContentDelegate;
GADAdReward *reward = rewardedAd.adReward;
NSDictionary *data = @{
@"type" : reward.type,
@"amount" : reward.amount,
};
NSMutableDictionary *data = [NSMutableDictionary dictionary];
if (reward.type != nil) {
[data setValue:reward.type forKey:@"type"];
}
if (reward.amount != nil) {
[data setValue:reward.amount forKey:@"amount"];
}
[RNGoogleAdsCommon sendAdEvent:GOOGLE_ADS_EVENT_REWARDED
requestId:requestId
type:GOOGLE_ADS_EVENT_REWARDED_LOADED
Expand All @@ -142,10 +145,13 @@ - (void)invalidate {
presentFromRootViewController:RCTSharedApplication().delegate.window.rootViewController
userDidEarnRewardHandler:^{
GADAdReward *reward = rewardedAd.adReward;
NSDictionary *data = @{
@"type" : reward.type,
@"amount" : reward.amount,
};
NSMutableDictionary *data = [NSMutableDictionary dictionary];
if (reward.type != nil) {
[data setValue:reward.type forKey:@"type"];
}
if (reward.amount != nil) {
[data setValue:reward.amount forKey:@"amount"];
}
[RNGoogleAdsCommon sendAdEvent:GOOGLE_ADS_EVENT_REWARDED
requestId:requestId
type:GOOGLE_ADS_EVENT_REWARDED_EARNED_REWARD
Expand Down
2 changes: 1 addition & 1 deletion lib/ads/InterstitialAd.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class InterstitialAd extends MobileAd {
}

const requestId = _interstitialRequest++;
return new InterstitialAd('interstitial', googleAds, requestId, adUnitId, options);
return new InterstitialAd('interstitial', googleAds(), requestId, adUnitId, options);
}

load() {
Expand Down
2 changes: 1 addition & 1 deletion lib/ads/RewardedAd.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class RewardedAd extends MobileAd {
}

const requestId = _rewardedRequest++;
return new RewardedAd('rewarded', googleAds, requestId, adUnitId, options);
return new RewardedAd('rewarded', googleAds(), requestId, adUnitId, options);
}

load() {
Expand Down
2 changes: 1 addition & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,6 @@ export const InterstitialAd: typeof GoogleAdsTypes.InterstitialAd;
export const RewardedAd: typeof GoogleAdsTypes.RewardedAd;
export const BannerAd: React.SFC<GoogleAdsTypes.BannerAd>;

declare const defaultExport: GoogleAdsTypes.Module & GoogleAdsTypes.Statics;
declare const defaultExport: () => GoogleAdsTypes.Module & GoogleAdsTypes.Statics;

export default defaultExport;
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,18 @@ class GoogleAdsModule extends Module {
// import { SDK_VERSION } from '@invertase/react-native-google-ads';
export const SDK_VERSION = version;

export default new GoogleAdsModule('AppName', {
const googleMobileAds = new GoogleAdsModule('AppName', {
statics,
version,
namespace,
nativeModuleName,
nativeEvents: ['google_ads_interstitial_event', 'google_ads_rewarded_event'],
});

export default () => {
return googleMobileAds;
};

export { default as AdsConsentDebugGeography } from './AdsConsentDebugGeography';
export { default as AdsConsentStatus } from './AdsConsentStatus';
export { default as MaxAdContentRating } from './MaxAdContentRating';
Expand Down