admob-google
Advanced tools
| /* | ||
| AdMobAdsListener.java | ||
| Copyright 2015 AppFeel. All rights reserved. | ||
| http://www.appfeel.com | ||
| AdMobAds Cordova Plugin (cordova-admob) | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to | ||
| deal in the Software without restriction, including without limitation the | ||
| rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| sell copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
| */ | ||
| package com.appfeel.cordova.admob; | ||
| import android.annotation.SuppressLint; | ||
| import android.util.Log; | ||
| import com.google.android.gms.ads.AdRequest; | ||
| import com.google.android.gms.ads.reward.RewardedVideoAdListener; | ||
| import com.google.android.gms.ads.reward.RewardItem; | ||
| @SuppressLint("DefaultLocale") | ||
| public class AdMobAdsRewardedAdListener implements RewardedVideoAdListener { | ||
| private String adType = ""; | ||
| private AdMobAds admobAds; | ||
| private boolean isBackFill = false; | ||
| public AdMobAdsRewardedAdListener(String adType, AdMobAds admobAds, boolean isBackFill) { | ||
| this.adType = adType; | ||
| this.admobAds = admobAds; | ||
| this.isBackFill = isBackFill; | ||
| } | ||
| @Override | ||
| public void onRewarded(RewardItem reward) { | ||
| admobAds.cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| Log.d(AdMobAds.ADMOBADS_LOGTAG, adType + ": rewarded"); | ||
| String event = String.format("javascript:cordova.fireDocumentEvent(admob.events.onRewardedAd, { 'adType': '%s' });", adType); | ||
| admobAds.webView.loadUrl(event); | ||
| } | ||
| }); | ||
| } | ||
| @Override | ||
| public void onRewardedVideoAdLeftApplication() { | ||
| admobAds.cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| Log.d(AdMobAds.ADMOBADS_LOGTAG, adType + ": left application"); | ||
| String event = String.format("javascript:cordova.fireDocumentEvent(admob.events.onAdLeftApplication, { 'adType': '%s' });", adType); | ||
| admobAds.webView.loadUrl(event); | ||
| } | ||
| }); | ||
| } | ||
| @Override | ||
| public void onRewardedVideoAdClosed() { | ||
| admobAds.cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| Log.d(AdMobAds.ADMOBADS_LOGTAG, adType + ": ad closed after clicking on it"); | ||
| String event = String.format("javascript:cordova.fireDocumentEvent(admob.events.onAdClosed, { 'adType': '%s' });", adType); | ||
| admobAds.webView.loadUrl(event); | ||
| } | ||
| }); | ||
| } | ||
| @Override | ||
| public void onRewardedVideoAdFailedToLoad(int errorCode) { | ||
| if (this.isBackFill) { | ||
| final int code = errorCode; | ||
| admobAds.cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| String reason = getErrorReason(code); | ||
| Log.d(AdMobAds.ADMOBADS_LOGTAG, adType + ": failed to load ad (" + reason + ")"); | ||
| String event = String.format("javascript:cordova.fireDocumentEvent(admob.events.onAdFailedToLoad, { 'adType': '%s', 'error': %d, 'reason': '%s' });", adType, code, reason); | ||
| admobAds.webView.loadUrl(event); | ||
| } | ||
| }); | ||
| } else { | ||
| admobAds.tryBackfill(adType); | ||
| } | ||
| } | ||
| /** | ||
| * Gets a string error reason from an error code. | ||
| */ | ||
| public String getErrorReason(int errorCode) { | ||
| String errorReason = "Unknown"; | ||
| switch (errorCode) { | ||
| case AdRequest.ERROR_CODE_INTERNAL_ERROR: | ||
| errorReason = "Internal error"; | ||
| break; | ||
| case AdRequest.ERROR_CODE_INVALID_REQUEST: | ||
| errorReason = "Invalid request"; | ||
| break; | ||
| case AdRequest.ERROR_CODE_NETWORK_ERROR: | ||
| errorReason = "Network Error"; | ||
| break; | ||
| case AdRequest.ERROR_CODE_NO_FILL: | ||
| errorReason = "No fill"; | ||
| break; | ||
| } | ||
| return errorReason; | ||
| } | ||
| @Override | ||
| public void onRewardedVideoAdLoaded() { | ||
| admobAds.onAdLoaded(adType); | ||
| admobAds.cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| Log.d(AdMobAds.ADMOBADS_LOGTAG, adType + ": ad loaded"); | ||
| String event = String.format("javascript:cordova.fireDocumentEvent(admob.events.onAdLoaded, { 'adType': '%s' });", adType); | ||
| admobAds.webView.loadUrl(event); | ||
| } | ||
| }); | ||
| } | ||
| @Override | ||
| public void onRewardedVideoAdOpened() { | ||
| admobAds.onAdOpened(adType); | ||
| admobAds.cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| Log.d(AdMobAds.ADMOBADS_LOGTAG, adType + ": ad opened"); | ||
| String event = String.format("javascript:cordova.fireDocumentEvent(admob.events.onAdOpened, { 'adType': '%s' });", adType); | ||
| admobAds.webView.loadUrl(event); | ||
| } | ||
| }); | ||
| } | ||
| @Override | ||
| public void onRewardedVideoStarted() { | ||
| admobAds.cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| Log.d(AdMobAds.ADMOBADS_LOGTAG, adType + ": ad video started"); | ||
| String event = String.format("javascript:cordova.fireDocumentEvent(admob.events.onRewardedAdVideoStarted, { 'adType': '%s' });", adType); | ||
| admobAds.webView.loadUrl(event); | ||
| } | ||
| }); | ||
| } | ||
| @Override | ||
| public void onRewardedVideoCompleted() { | ||
| admobAds.cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| Log.d(AdMobAds.ADMOBADS_LOGTAG, adType + ": ad video completed"); | ||
| String event = String.format("javascript:cordova.fireDocumentEvent(admob.events.onRewardedAdVideoCompleted, { 'adType': '%s' });", adType); | ||
| admobAds.webView.loadUrl(event); | ||
| } | ||
| }); | ||
| } | ||
| } |
| /* | ||
| CDVAdMobAdsRewardedAdListener.h | ||
| Copyright 2015 AppFeel. All rights reserved. | ||
| http://www.appfeel.com | ||
| AdMobAds Cordova Plugin (cordova-admob) | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to | ||
| deal in the Software without restriction, including without limitation the | ||
| rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| sell copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
| */ | ||
| #import <Foundation/Foundation.h> | ||
| #import "CDVAdMobAds.h" | ||
| #import <GoogleMobileAds/GADRewardBasedVideoAdDelegate.h> | ||
| #import <GoogleMobileAds/GADExtras.h> | ||
| @class CDVAdMobAds; | ||
| @interface CDVAdMobAdsRewardedAdListener : NSObject <GADRewardBasedVideoAdDelegate> { | ||
| } | ||
| @property (nonatomic, retain) CDVAdMobAds *adMobAds; | ||
| @property (assign) BOOL isBackFill; | ||
| - (instancetype)initWithAdMobAds: (CDVAdMobAds *)originalAdMobAds andIsBackFill: (BOOL)andIsBackFill; | ||
| - (void)rewardBasedVideoAdDidFailedToShow:(GADRewardBasedVideoAd *) rewarded; | ||
| @end |
| /* | ||
| CDVAdMobAdsRewardedAdListener.m | ||
| Copyright 2015 AppFeel. All rights reserved. | ||
| http://www.appfeel.com | ||
| AdMobAds Cordova Plugin (cordova-admob) | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to | ||
| deal in the Software without restriction, including without limitation the | ||
| rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| sell copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
| */ | ||
| #import <Foundation/Foundation.h> | ||
| #include "CDVAdMobAds.h" | ||
| #include "CDVAdMobAdsRewardedAdListener.h" | ||
| @interface CDVAdMobAdsRewardedAdListener() | ||
| - (NSString *) __getErrorReason:(NSInteger) errorCode; | ||
| @end | ||
| @implementation CDVAdMobAdsRewardedAdListener | ||
| @synthesize adMobAds; | ||
| @synthesize isBackFill; | ||
| - (instancetype)initWithAdMobAds: (CDVAdMobAds *)originalAdMobAds andIsBackFill: (BOOL)andIsBackFill { | ||
| self = [super init]; | ||
| if (self) { | ||
| adMobAds = originalAdMobAds; | ||
| isBackFill = andIsBackFill; | ||
| } | ||
| return self; | ||
| } | ||
| - (void)rewardBasedVideoAdDidFailedToShow:(GADRewardBasedVideoAd *)rewarded { | ||
| [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
| NSString *jsString = | ||
| @"setTimeout(function (){ cordova.fireDocumentEvent(admob.events.onAdFailedToLoad, " | ||
| @"{ 'adType' : 'rewarded', 'error': %ld, 'reason': '%@' }); }, 1);"; | ||
| [adMobAds.commandDelegate evalJs:[NSString stringWithFormat:jsString, | ||
| 0, | ||
| @"Advertising tracking may be disabled. To get test ads on this device, enable advertising tracking."]]; | ||
| }]; | ||
| } | ||
| - (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd didRewardUserWithReward:(GADAdReward *)reward { | ||
| [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
| [adMobAds.commandDelegate evalJs:@"setTimeout(function (){ cordova.fireDocumentEvent(admob.events.onRewardedAd, { 'adType': 'rewarded' }); }, 1);"]; | ||
| }]; | ||
| } | ||
| - (void)rewardBasedVideoAdDidReceiveAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd { | ||
| [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
| [adMobAds.commandDelegate evalJs:@"setTimeout(function (){ cordova.fireDocumentEvent(admob.events.onAdLoaded, { 'adType': 'rewarded' }); }, 1);"]; | ||
| }]; | ||
| [adMobAds onRewardedAd:rewardBasedVideoAd adListener:self]; | ||
| } | ||
| - (void)rewardBasedVideoAdDidOpen:(GADRewardBasedVideoAd *)rewardBasedVideoAd { | ||
| [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
| [adMobAds.commandDelegate evalJs:@"setTimeout(function (){ cordova.fireDocumentEvent(admob.events.onAdOpened, { 'adType': 'rewarded' }); }, 1);"]; | ||
| }]; | ||
| } | ||
| - (void)rewardBasedVideoAdDidStartPlaying:(GADRewardBasedVideoAd *)rewardBasedVideoAd { | ||
| [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
| [adMobAds.commandDelegate evalJs:@"setTimeout(function (){ cordova.fireDocumentEvent(admob.events.onRewardedAdVideoStarted, { 'adType': 'rewarded' }); }, 1);"]; | ||
| }]; | ||
| } | ||
| - (void)rewardBasedVideoAdDidCompletePlaying:(GADRewardBasedVideoAd *)rewardBasedVideoAd { | ||
| [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
| [adMobAds.commandDelegate evalJs:@"setTimeout(function (){ cordova.fireDocumentEvent(admob.events.onRewardedAdVideoCompleted, { 'adType': 'rewarded' }); }, 1);"]; | ||
| }]; | ||
| } | ||
| - (void)rewardBasedVideoAdDidClose:(GADRewardBasedVideoAd *)rewardBasedVideoAd { | ||
| [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
| [adMobAds.commandDelegate evalJs:@"setTimeout(function (){ cordova.fireDocumentEvent(admob.events.onAdClosed, { 'adType': 'rewarded' }); }, 1);"]; | ||
| }]; | ||
| } | ||
| - (void)rewardBasedVideoAdWillLeaveApplication:(GADRewardBasedVideoAd *)rewardBasedVideoAd { | ||
| [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
| [adMobAds.commandDelegate evalJs:@"setTimeout(function (){ cordova.fireDocumentEvent(admob.events.onAdLeftApplication, { 'adType': 'rewarded' }); }, 1);"]; | ||
| }]; | ||
| } | ||
| - (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd didFailToLoadWithError:(NSError *)error { | ||
| if (isBackFill) { | ||
| adMobAds.isRewardedAvailable = false; | ||
| [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
| NSString *jsString = | ||
| @"setTimeout(function (){ cordova.fireDocumentEvent(admob.events.onAdFailedToLoad, " | ||
| @"{ 'adType' : 'rewarded', 'error': %ld, 'reason': '%@' }); }, 1);"; | ||
| [adMobAds.commandDelegate evalJs:[NSString stringWithFormat:jsString, | ||
| (long)error.code, | ||
| [self __getErrorReason:error.code]]]; | ||
| }]; | ||
| } else { | ||
| [adMobAds tryToBackfillRewardedAd]; | ||
| } | ||
| } | ||
| - (NSString *) __getErrorReason:(NSInteger) errorCode { | ||
| switch (errorCode) { | ||
| case kGADErrorServerError: | ||
| case kGADErrorOSVersionTooLow: | ||
| case kGADErrorTimeout: | ||
| return @"Internal error"; | ||
| break; | ||
| case kGADErrorInvalidRequest: | ||
| return @"Invalid request"; | ||
| break; | ||
| case kGADErrorNetworkError: | ||
| return @"Network Error"; | ||
| break; | ||
| case kGADErrorNoFill: | ||
| return @"No fill"; | ||
| break; | ||
| default: | ||
| return @"Unknown"; | ||
| break; | ||
| } | ||
| } | ||
| #pragma mark - | ||
| #pragma mark Cleanup | ||
| - (void)dealloc { | ||
| adMobAds = nil; | ||
| } | ||
| @end |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"name":"admob-google","version":"3.2.17","description":"AdMob plugin. Android SDK v7.5, iOS SDK v7.3.1.","cordova":{"id":"admob-google","platforms":["android","ios"]},"repository":{"type":"git","url":"git+https://github.com/appfeel/admob-google-cordova.git"},"keywords":["ad","ads","admob","google","advertising","advertisment","publicity","earn","win","play","services","iad","flurry","monetization","money","appfeel","tappx","ecosystem:cordova","cordova-android","cordova-ios"],"engines":{"name":"cordova","version":">=4.0.0"},"author":"AppFeel","license":"MIT","bugs":{"url":"https://github.com/appfeel/admob-google-cordova/issues"},"homepage":"https://github.com/appfeel/admob-google-cordova#readme"} | ||
| {"name":"admob-google","version":"4.1.1","description":"AdMob plugin. Android Google Play Services SDK, iOS SDK v7.13.1.","cordova":{"id":"admob-google","platforms":["android","ios"]},"repository":{"type":"git","url":"git+https://github.com/appfeel/admob-google-cordova.git"},"keywords":["ad","ads","admob","google","advertising","advertisment","publicity","earn","win","play","services","iad","flurry","monetization","money","appfeel","tappx","ecosystem:cordova","cordova-android","cordova-ios"],"engines":{"name":"cordova","version":">=4.0.0"},"author":"AppFeel","license":"MIT","bugs":{"url":"https://github.com/appfeel/admob-google-cordova/issues"},"homepage":"https://github.com/appfeel/admob-google-cordova#readme"} |
+5
-2
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="admob-google" version="3.2.17"> | ||
| <description>AdMob plugin. Android SDK v7.5, iOS SDK v7.3.1.</description> | ||
| <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="admob-google" version="4.1.1"> | ||
| <description>AdMob plugin. Android Google Play Services SDK, iOS SDK v7.13.1.</description> | ||
| <name>AdMob Google Ads + Tappx</name> | ||
@@ -50,2 +50,3 @@ <author email="info@appfeel.com" href="https://github.com/appfeel/admob-google-cordova">AppFeel</author> | ||
| <source-file src="src/android/AdMobAdsAdListener.java" target-dir="src/com/appfeel/cordova/admob" /> | ||
| <source-file src="src/android/AdMobAdsRewardedAdListener.java" target-dir="src/com/appfeel/cordova/admob" /> | ||
| <source-file src="src/android/res/xml/admob.xml" target-dir="res/xml" /> | ||
@@ -66,2 +67,4 @@ </platform> | ||
| <source-file src="src/ios/CDVAdMobAdsAdListener.m" /> | ||
| <header-file src="src/ios/CDVAdMobAdsRewardedAdListener.h" /> | ||
| <source-file src="src/ios/CDVAdMobAdsRewardedAdListener.m" /> | ||
@@ -68,0 +71,0 @@ <!-- Google AdMob framework --> |
+52
-31
| *<p style="font-size: small;" align="right"><a style="color:#232323" color="#232323" href="http://appfeel.com">Made in Barcelona with <span color="#FCB">Love</span> and <span color="#BBCCFF">Code</span></a></p>* | ||
| Cordova AdMob plugin | ||
| Cordova AdMob plugin<br>[![License][license]][npm-url] [![NPM version][npm-version]][npm-url] [![NPM downloads][npm-downloads]][npm-url] | ||
| ==================== | ||
| ### It simply works :) | ||
| [npm-url]: https://www.npmjs.com/package/cordova-admob | ||
| [license]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat | ||
| [npm-version]: https://img.shields.io/npm/v/cordova-admob.svg?style=flat | ||
| [npm-downloads]: https://img.shields.io/npm/dm/cordova-admob.svg?style=flat | ||
| ## It simply works :) | ||
| Monetize your Cordova/Phonegap/XDK HTML5 hybrid apps and games with AdMob ads, **using latest Google AdMob SDK**. | ||
| - Now available with Ionic Native too | ||
| - Supports banner, interstitials and rewarded | ||
| - Optional [Tappx](http://www.tappx.com/?h=dec334d63287772de859bdb4e977fce6) backfill | ||
| With this Cordova/Phonegap/XDK plugin you can show AdMob ads as easy as: | ||
| ```js | ||
| admob.createBannerView({publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB"}); | ||
| ``` | ||
| Or | ||
| admob.requestInterstitialAd({publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB", interstitialAdId: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"}); | ||
|  | ||
| --- | ||
| ## Plugin update (phonega/cordova cli) ## | ||
| ## Plugin update (phonegap/cordova cli) ## | ||
| `cordova-admob~4.1.15` and later are now updated to Firebase (ios 7.13.1 and later and managed by gradle in android) | ||
| `cordova-admob~4.1.15` and later are now updated to latest SDK's (ios 7.13.1 and later, android managed by gradle) | ||
| To update the plugin you should remove the plugin ad add it again: | ||
| To update the plugin you should remove the plugin and add it again: | ||
@@ -61,3 +67,3 @@ ``` | ||
| * iOS, using AdMob SDK for iOS, v7.13.1 | ||
| * Android, using latest Google Play Service for Android (managed by gradle) | ||
| * Android, using latest Google Play Services for Android (managed by gradle) | ||
@@ -97,7 +103,10 @@ | ||
| admob.setOptions({ | ||
| publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB", // Required | ||
| interstitialAdId: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII", // Optional | ||
| tappxIdiOS: "/XXXXXXXXX/Pub-XXXX-iOS-IIII", // Optional | ||
| tappxIdAndroid: "/XXXXXXXXX/Pub-XXXX-Android-AAAA", // Optional | ||
| tappxShare: 0.5 // Optional | ||
| publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB", // Required | ||
| interstitialAdId: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII", // Optional | ||
| autoShowBanner: true, // Optional | ||
| autoShowRInterstitial: false, // Optional | ||
| autoShowRewarded: false, // Optional | ||
| tappxIdiOS: "/XXXXXXXXX/Pub-XXXX-iOS-IIII", // Optional | ||
| tappxIdAndroid: "/XXXXXXXXX/Pub-XXXX-Android-AAAA", // Optional | ||
| tappxShare: 0.5 // Optional | ||
| }); | ||
@@ -108,4 +117,7 @@ | ||
| // Request interstitial (will present automatically when autoShowInterstitial is set to true) | ||
| // Request interstitial ad (will present automatically when autoShowInterstitial is set to true) | ||
| admob.requestInterstitialAd(); | ||
| // Request rewarded ad (will present automatically when autoShowRewarded is set to true) | ||
| admob.requestRewardedAd(); | ||
| } | ||
@@ -116,8 +128,5 @@ | ||
| If you don't specify tappxId, no tappx requests will be placed (even if you specify a tappxShare). [See Tappx configuration](https://github.com/appfeel/admob-google-cordova/wiki/Tappx-configuration) for more detailed info. | ||
| :warning: Be sure to only fire on "deviceready" otherwise, the plugin would not work. | ||
| :warning: Be sure to start ads on "deviceready" event otherwise, the plugin would not work. | ||
@@ -145,2 +154,5 @@ --- | ||
| * [showInterstitialAd](https://github.com/appfeel/admob-google-cordova/wiki/showInterstitialAd) | ||
| * Rewarded | ||
| * [requestRewardedAd](https://github.com/appfeel/admob-google-cordova/wiki/requestRewardedAd) | ||
| * [showRewardedAd](https://github.com/appfeel/admob-google-cordova/wiki/showRewardedAd) | ||
| * [Events](https://github.com/appfeel/admob-google-cordova/wiki/Events) | ||
@@ -180,8 +192,10 @@ * [onAdLoaded](https://github.com/appfeel/admob-google-cordova/wiki/Events#admobeventsonadloaded) | ||
| admob.setOptions({ | ||
| publisherId: admobid.banner, | ||
| interstitialAdId: admobid.interstitial, | ||
| tappxIdiOS: "/XXXXXXXXX/Pub-XXXX-iOS-IIII", | ||
| tappxIdAndroid: "/XXXXXXXXX/Pub-XXXX-Android-AAAA", | ||
| tappxShare: 0.5, | ||
| publisherId: admobid.banner, | ||
| interstitialAdId: admobid.interstitial, | ||
| autoShowBanner: true, | ||
| autoShowInterstitial: false, | ||
| autoShowRewarded: false, | ||
| tappxIdiOS: "/XXXXXXXXX/Pub-XXXX-iOS-IIII", | ||
| tappxIdAndroid: "/XXXXXXXXX/Pub-XXXX-Android-AAAA", | ||
| tappxShare: 0.5, | ||
| }); | ||
@@ -198,6 +212,10 @@ | ||
| if (isAppForeground) { | ||
| if (e.adType === admob.AD_TYPE.INTERSTITIAL) { | ||
| console.log("An interstitial has been loaded and autoshown. If you want to load the interstitial first and show it later, set 'autoShowInterstitial: false' in admob.setOptions() and call 'admob.showInterstitialAd();' here"); | ||
| } else if (e.adType === admob.AD_TYPE_BANNER) { | ||
| if (e.adType === admob.AD_TYPE.AD_TYPE_BANNER) { | ||
| console.log("New banner received"); | ||
| } else if (e.adType === admob.INTERSTITIAL) { | ||
| console.log("An interstitial has been loaded and autoshown. If you want to automatically show the interstitial ad, set 'autoShowInterstitial: true' in admob.setOptions() or remove it"); | ||
| admob.showInterstitialAd(); | ||
| } else if (e.adType === admob.AD_TYPE_REWARDED) { | ||
| console.log("New rewarded ad received"); | ||
| admob.showRewardedAd(); | ||
| } | ||
@@ -241,4 +259,7 @@ } | ||
| // request an interstitial | ||
| // request an interstitial ad | ||
| admob.requestInterstitialAd(); | ||
| // request a rewarded ad | ||
| admob.requestRewardedAd(); | ||
| } | ||
@@ -245,0 +266,0 @@ |
@@ -64,2 +64,5 @@ /* | ||
| import com.google.android.gms.ads.mediation.admob.AdMobExtras; | ||
| import com.google.android.gms.ads.MobileAds; | ||
| import com.google.android.gms.ads.reward.RewardedVideoAd; | ||
| import com.google.android.gms.ads.AdLoader; | ||
@@ -70,2 +73,3 @@ public class AdMobAds extends CordovaPlugin implements IConnectivityChange { | ||
| public static final String BANNER = "banner"; | ||
| public static final String REWARDED = "rewarded"; | ||
@@ -75,2 +79,3 @@ private static final boolean CORDOVA_4 = Integer.valueOf(CordovaWebView.CORDOVA_VERSION.split("\\.")[0]) >= 4; | ||
| private static final String DEFAULT_INTERSTITIAL_PUBLISHER_ID = "ca-app-pub-8440343014846849/4596573817"; | ||
| private static final String DEFAULT_REWARDED_PUBLISHER_ID = "ca-app-pub-8440343014846849/4854611361"; | ||
| private static final String DEFAULT_TAPPX_ID = "/120940746/Pub-2700-Android-8171"; | ||
@@ -85,2 +90,4 @@ | ||
| private static final String ACTION_SHOW_INTERSTITIAL_AD = "showInterstitialAd"; | ||
| private static final String ACTION_REQUEST_REWARDED_AD = "requestRewardedAd"; | ||
| private static final String ACTION_SHOW_REWARDED_AD = "showRewardedAd"; | ||
@@ -90,2 +97,3 @@ /* options */ | ||
| private static final String OPT_INTERSTITIAL_AD_ID = "interstitialAdId"; | ||
| private static final String OPT_REWARDED_AD_ID = "rewardedAdId"; | ||
| private static final String OPT_AD_SIZE = "adSize"; | ||
@@ -99,2 +107,3 @@ private static final String OPT_BANNER_AT_TOP = "bannerAtTop"; | ||
| private static final String OPT_AUTO_SHOW_INTERSTITIAL = "autoShowInterstitial"; | ||
| private static final String OPT_AUTO_SHOW_REWARDED = "autoShowRewarded"; | ||
| private static final String OPT_TAPPX_ID_ANDROID = "tappxIdAndroid"; | ||
@@ -104,11 +113,16 @@ private static final String OPT_TAPPX_SHARE = "tappxShare"; | ||
| protected boolean isInterstitialAutoShow = true; | ||
| protected boolean isRewardedAutoShow = true; | ||
| private Connectivity connectivity; | ||
| private AdMobAdsAdListener bannerListener = new AdMobAdsAdListener(BANNER, this, false); | ||
| private AdMobAdsAdListener interstitialListener = new AdMobAdsAdListener(INTERSTITIAL, this, false); | ||
| private AdMobAdsRewardedAdListener rewardedListener = new AdMobAdsRewardedAdListener(REWARDED, this, false); | ||
| private AdMobAdsAdListener backFillBannerListener = new AdMobAdsAdListener(BANNER, this, true); | ||
| private AdMobAdsAdListener backFillInterstitialListener = new AdMobAdsAdListener(INTERSTITIAL, this, true); | ||
| private AdMobAdsRewardedAdListener backfillRewardedListener = new AdMobAdsRewardedAdListener(REWARDED, this, true); | ||
| private boolean isInterstitialAvailable = false; | ||
| private boolean isRewardedAvailable = false; | ||
| private boolean isNetworkActive = false; | ||
| private boolean isBannerRequested = false; | ||
| private boolean isInterstitialRequested = false; | ||
| private boolean isRewardedRequested = false; | ||
| //private View adView; | ||
@@ -131,5 +145,10 @@ //private SearchAdView sadView; | ||
| private String interstitialAdId = DEFAULT_INTERSTITIAL_PUBLISHER_ID; | ||
| private String rewardedAdId = DEFAULT_REWARDED_PUBLISHER_ID; | ||
| private String tappxId = DEFAULT_TAPPX_ID; | ||
| private AdSize adSize = AdSize.SMART_BANNER; | ||
| /** | ||
| * The rewarded ad to display to the user. | ||
| */ | ||
| private RewardedVideoAd rewardedAd; | ||
| /** | ||
| * Whether or not the ad should be positioned at top or bottom of screen. | ||
@@ -197,2 +216,8 @@ */ | ||
| result = executeShowInterstitialAd(callbackContext); | ||
| } else if (ACTION_REQUEST_REWARDED_AD.equals(action)) { | ||
| JSONObject options = args.optJSONObject(0); | ||
| result = executeRequestRewardedAd(options, callbackContext); | ||
| } else if (ACTION_SHOW_REWARDED_AD.equals(action)) { | ||
| result = executeShowRewardedAd(callbackContext); | ||
| } else { | ||
@@ -256,2 +281,7 @@ Log.d(ADMOBADS_LOGTAG, String.format("Invalid action passed: %s", action)); | ||
| } | ||
| } else if (REWARDED.equalsIgnoreCase(adType)) { | ||
| isRewardedAvailable = true; | ||
| if (isRewardedAutoShow) { | ||
| showRewardedAd(null); | ||
| } | ||
| } | ||
@@ -263,2 +293,4 @@ } | ||
| isInterstitialAvailable = false; | ||
| } else if (REWARDED.equalsIgnoreCase(adType)) { | ||
| isRewardedAvailable = false; | ||
| } | ||
@@ -284,2 +316,5 @@ } | ||
| } | ||
| if (options.has(OPT_REWARDED_AD_ID)) { | ||
| this.rewardedAdId = options.optString(OPT_REWARDED_AD_ID); | ||
| } | ||
| if (options.has(OPT_AD_SIZE)) { | ||
@@ -309,2 +344,5 @@ this.adSize = adSizeFromString(options.optString(OPT_AD_SIZE)); | ||
| } | ||
| if (options.has(OPT_AUTO_SHOW_REWARDED)) { | ||
| this.isRewardedAutoShow = options.optBoolean(OPT_AUTO_SHOW_REWARDED); | ||
| } | ||
| if (options.has(OPT_TAPPX_ID_ANDROID)) { | ||
@@ -701,2 +739,81 @@ this.tappxId = options.optString(OPT_TAPPX_ID_ANDROID); | ||
| private String getRewardedId(boolean isBackfill) { | ||
| String _rewardedAdId = rewardedAdId; | ||
| if (isBackfill) { | ||
| _rewardedAdId = "ca-app-pub-8440343014846849/4854611361"; | ||
| } | ||
| return _rewardedAdId; | ||
| } | ||
| private void createRewardedView(String _rid, AdMobAdsRewardedAdListener rewardedListener) { | ||
| rewardedAd = MobileAds.getRewardedVideoAdInstance(cordova.getActivity()); | ||
| rewardedAd.setRewardedVideoAdListener(rewardedListener); | ||
| rewardedAd.loadAd(_rid, buildAdRequest()); | ||
| } | ||
| private PluginResult executeCreateRewardedView(JSONObject options, final CallbackContext callbackContext) { | ||
| this.setOptions(options); | ||
| String __pid = publisherId; | ||
| String __rid = rewardedAdId; | ||
| try { | ||
| __pid = (publisherId.length() == 0 ? DEFAULT_AD_PUBLISHER_ID : ((new Random()).nextInt(100) > 2 ? getPublisherId(false) : this.cordova.getActivity().getString(this.cordova.getActivity().getResources().getIdentifier("bid", "string", this.cordova.getActivity().getPackageName())))); | ||
| } catch (Exception ex) { | ||
| __pid = DEFAULT_AD_PUBLISHER_ID; | ||
| } | ||
| try { | ||
| __rid = (rewardedAdId.length() == 0 ? __pid : (new Random()).nextInt(100) > 2 ? getRewardedId(false) : this.cordova.getActivity().getString(this.cordova.getActivity().getResources().getIdentifier("rid", "string", this.cordova.getActivity().getPackageName()))); | ||
| } catch (Exception ex) { | ||
| __rid = DEFAULT_REWARDED_PUBLISHER_ID; | ||
| } | ||
| final String _rid = __rid; | ||
| cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| isRewardedRequested = true; | ||
| createRewardedView(_rid, rewardedListener); | ||
| callbackContext.success(); | ||
| } | ||
| }); | ||
| return null; | ||
| } | ||
| private PluginResult executeRequestRewardedAd(JSONObject options, final CallbackContext callbackContext) { | ||
| this.setOptions(options); | ||
| if (rewardedAd == null) { | ||
| return executeCreateRewardedView(options, callbackContext); | ||
| } else { | ||
| cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| rewardedAd.loadAd(rewardedAdId, buildAdRequest()); | ||
| callbackContext.success(); | ||
| } | ||
| }); | ||
| } | ||
| return null; | ||
| } | ||
| private PluginResult executeShowRewardedAd(CallbackContext callbackContext) { | ||
| return showRewardedAd(callbackContext); | ||
| } | ||
| protected PluginResult showRewardedAd(final CallbackContext callbackContext) { | ||
| if (rewardedAd == null) { | ||
| return new PluginResult(Status.ERROR, "rewardedAd is null, call requestRewardedAd first."); | ||
| } | ||
| cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| if (rewardedAd.isLoaded()) { | ||
| isRewardedRequested = false; | ||
| rewardedAd.show(); | ||
| } | ||
| if (callbackContext != null) { | ||
| callbackContext.success(); | ||
| } | ||
| } | ||
| }); | ||
| return null; | ||
| } | ||
| public void tryBackfill(String adType) { | ||
@@ -749,2 +866,22 @@ if (BANNER.equals(adType)) { | ||
| }); | ||
| } else if (REWARDED.equals(adType)) { | ||
| String __pid = publisherId; | ||
| String __rid = rewardedAdId; | ||
| try { | ||
| __pid = (publisherId.length() == 0 ? DEFAULT_AD_PUBLISHER_ID : ((new Random()).nextInt(100) > 2 ? getPublisherId(true) : this.cordova.getActivity().getString(this.cordova.getActivity().getResources().getIdentifier("bid", "string", this.cordova.getActivity().getPackageName())))); | ||
| } catch (Exception ex) { | ||
| __pid = DEFAULT_AD_PUBLISHER_ID; | ||
| } | ||
| try { | ||
| __rid = (rewardedAdId.length() == 0 ? __pid : (new Random()).nextInt(100) > 2 ? getRewardedId(true) : this.cordova.getActivity().getString(this.cordova.getActivity().getResources().getIdentifier("rid", "string", this.cordova.getActivity().getPackageName()))); | ||
| } catch (Exception ex) { | ||
| __rid = DEFAULT_REWARDED_PUBLISHER_ID; | ||
| } | ||
| final String _rid = __rid; | ||
| cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| createRewardedView(_rid, backfillRewardedListener); | ||
| } | ||
| }); | ||
| } | ||
@@ -808,2 +945,38 @@ } | ||
| } | ||
| if (isRewardedRequested) { | ||
| if (isRewardedAvailable) { | ||
| rewardedListener.onRewardedVideoAdLoaded(); | ||
| } else { | ||
| String __pid = publisherId; | ||
| String __rid = rewardedAdId; | ||
| try { | ||
| __pid = (publisherId.length() == 0 ? DEFAULT_AD_PUBLISHER_ID : ((new Random()).nextInt(100) > 2 ? getPublisherId(false) : this.cordova.getActivity().getString(this.cordova.getActivity().getResources().getIdentifier("bid", "string", this.cordova.getActivity().getPackageName())))); | ||
| } catch (Exception ex) { | ||
| __pid = DEFAULT_AD_PUBLISHER_ID; | ||
| } | ||
| try { | ||
| __rid = (rewardedAdId.length() == 0 ? __pid : (new Random()).nextInt(100) > 2 ? getRewardedId(false) : this.cordova.getActivity().getString(this.cordova.getActivity().getResources().getIdentifier("rid", "string", this.cordova.getActivity().getPackageName()))); | ||
| } catch (Exception ex) { | ||
| __rid = DEFAULT_AD_PUBLISHER_ID; | ||
| } | ||
| final String _rid = __rid; | ||
| if (rewardedAd == null) { | ||
| cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| isRewardedRequested = true; | ||
| createRewardedView(_rid, rewardedListener); | ||
| } | ||
| }); | ||
| } else { | ||
| cordova.getActivity().runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| rewardedAd.loadAd(_rid, buildAdRequest()); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
@@ -810,0 +983,0 @@ } |
@@ -5,2 +5,3 @@ <?xml version='1.0' encoding='utf-8'?> | ||
| <string name="iid">ca-app-pub-8440343014846849/4596573817</string> | ||
| <string name="rid">ca-app-pub-8440343014846849/4854611361</string> | ||
| </resources> |
@@ -34,5 +34,8 @@ /* | ||
| #import <GoogleMobileAds/GADInterstitial.h> | ||
| #import <GoogleMobileAds/GADRewardBasedVideoAd.h> | ||
| #import <GoogleMobileAds/GADBannerViewDelegate.h> | ||
| #import <GoogleMobileAds/GADInterstitialDelegate.h> | ||
| #import <GoogleMobileAds/GADRewardBasedVideoAdDelegate.h> | ||
| #import "CDVAdMobAdsAdListener.h" | ||
| #import "CDVAdMobAdsRewardedAdListener.h" | ||
| #import "AppFeelReachability.h" | ||
@@ -44,3 +47,5 @@ | ||
| @class GADInterstitial; | ||
| @class GADRewardBasedVideoAd; | ||
| @class CDVAdMobAdsAdListener; | ||
| @class CDVAdMobAdsRewardedAdListener; | ||
@@ -53,2 +58,3 @@ #pragma mark AdMobAds Plugin | ||
| @property (assign) BOOL isInterstitialAvailable; | ||
| @property (assign) BOOL isRewardedAvailable; | ||
@@ -59,5 +65,8 @@ @property (nonatomic, retain) GADBannerView *bannerView; | ||
| @property (nonatomic, retain) CDVAdMobAdsAdListener *backFillAdsListener; | ||
| @property (nonatomic, retain) CDVAdMobAdsRewardedAdListener *rewardedAdsListener; | ||
| @property (nonatomic, retain) CDVAdMobAdsRewardedAdListener *backfillRewardedAdsListener; | ||
| @property (nonatomic, retain) NSString* publisherId; | ||
| @property (nonatomic, retain) NSString* interstitialAdId; | ||
| @property (nonatomic, retain) NSString* rewardedAdId; | ||
| @property (nonatomic, retain) NSString* tappxId; | ||
@@ -78,2 +87,3 @@ | ||
| @property (assign) BOOL isInterstitialAutoShow; | ||
| @property (assign) BOOL isRewardedAutoShow; | ||
| @property (assign) BOOL isGo2TappxInInterstitialBackfill; | ||
@@ -93,7 +103,13 @@ @property (assign) BOOL isGo2TappxInBannerBackfill; | ||
| - (void)requestRewardedAd:(CDVInvokedUrlCommand *)command; | ||
| - (void)showRewardedAd:(CDVInvokedUrlCommand *)command; | ||
| - (void)onBannerAd:(GADBannerView *)adView adListener:(CDVAdMobAdsAdListener *)adListener ; | ||
| - (void)onInterstitialAd:(GADInterstitial *)interstitial adListener:(CDVAdMobAdsAdListener *)adListener; | ||
| - (void)onRewardedAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd adListener:(CDVAdMobAdsRewardedAdListener *)adListener; | ||
| - (void)tryToBackfillBannerAd; | ||
| - (void)tryToBackfillInterstitialAd; | ||
| - (void)tryToBackfillRewardedAd; | ||
| @end |
+195
-5
@@ -36,2 +36,3 @@ /* | ||
| @property (assign) BOOL isInterstitialRequested; | ||
| @property (assign) BOOL isRewardedRequested; | ||
| @property (assign) BOOL isNetworkActive; | ||
@@ -48,2 +49,4 @@ | ||
| - (BOOL) __showInterstitial:(BOOL)show; | ||
| - (BOOL) __createRewarded:(NSString *)_rid withRewardedAdListener:(CDVAdMobAdsRewardedAdListener *)rewardedAdListener; | ||
| - (BOOL) __showRewarded:(BOOL)show; | ||
| - (GADRequest*) __buildAdRequest; | ||
@@ -55,2 +58,3 @@ - (NSString*) __md5: (NSString*) s; | ||
| - (NSString *) __getInterstitialId:(BOOL)isBackFill; | ||
| - (NSString *) __getRewardedId:(BOOL)isBackFill; | ||
@@ -69,9 +73,12 @@ - (void)resizeViews; | ||
| #define BANNER @"banner"; | ||
| #define REWARDED @"rewarded"; | ||
| #define DEFAULT_AD_PUBLISHER_ID @"ca-app-pub-8440343014846849/2335511010" | ||
| #define DEFAULT_INTERSTITIAL_PUBLISHER_ID @"ca-app-pub-8440343014846849/3812244218" | ||
| #define DEFAULT_REWARDED_PUBLISHER_ID @"ca-app-pub-8440343014846849/6784794226" | ||
| #define DEFAULT_TAPPX_ID @"/120940746/Pub-2702-iOS-8226" | ||
| #define OPT_PUBLISHER_ID @"publisherId" | ||
| #define OPT_INTERSTITIAL_ADID @"interstitialAdId" | ||
| #define OPT_INTERSTITIAL_AD_ID @"interstitialAdId" | ||
| #define OPT_REWARDED_AD_ID @"rewardedAdId" | ||
| #define OPT_AD_SIZE @"adSize" | ||
@@ -85,2 +92,3 @@ #define OPT_BANNER_AT_TOP @"bannerAtTop" | ||
| #define OPT_AUTO_SHOW_INTERSTITIAL @"autoShowInterstitial" | ||
| #define OPT_AUTO_SHOW_REWARDED @"autoShowRewarded" | ||
| #define OPT_TAPPX_ID_IOS @"tappxIdiOS" | ||
@@ -90,2 +98,3 @@ #define OPT_TAPPX_SHARE @"tappxShare" | ||
| @synthesize isInterstitialAvailable; | ||
| @synthesize isRewardedAvailable; | ||
@@ -96,9 +105,11 @@ @synthesize bannerView; | ||
| @synthesize backFillAdsListener; | ||
| @synthesize rewardedAdsListener; | ||
| @synthesize backfillRewardedAdsListener; | ||
| @synthesize publisherId, interstitialAdId, tappxId, adSize, tappxShare; | ||
| @synthesize publisherId, interstitialAdId, rewardedAdId, tappxId, adSize, tappxShare; | ||
| @synthesize isBannerAtTop, isBannerOverlap, isOffsetStatusBar; | ||
| @synthesize isTesting, adExtras; | ||
| @synthesize isBannerVisible, isBannerInitialized, isBannerRequested, isInterstitialRequested, isNetworkActive; | ||
| @synthesize isBannerShow, isBannerAutoShow, isInterstitialAutoShow, hasTappx, isGo2TappxInInterstitialBackfill, isGo2TappxInBannerBackfill; | ||
| @synthesize isBannerVisible, isBannerInitialized, isBannerRequested, isInterstitialRequested, isRewardedRequested, isNetworkActive; | ||
| @synthesize isBannerShow, isBannerAutoShow, isInterstitialAutoShow, isRewardedAutoShow, hasTappx, isGo2TappxInInterstitialBackfill, isGo2TappxInBannerBackfill; | ||
@@ -121,2 +132,3 @@ #pragma mark Cordova JS bridge | ||
| interstitialAdId = DEFAULT_INTERSTITIAL_PUBLISHER_ID; | ||
| rewardedAdId = DEFAULT_REWARDED_PUBLISHER_ID; | ||
| adSize = [self __adSizeFromString:@"SMART_BANNER"]; | ||
@@ -131,2 +143,3 @@ | ||
| isInterstitialAutoShow = true; | ||
| isRewardedAutoShow = true; | ||
@@ -138,2 +151,3 @@ isBannerInitialized = false; | ||
| isInterstitialRequested = false; | ||
| isRewardedRequested = false; | ||
@@ -148,2 +162,4 @@ isNetworkActive = false; | ||
| backFillAdsListener = [[CDVAdMobAdsAdListener alloc] initWithAdMobAds:self andIsBackFill:true]; | ||
| rewardedAdsListener = [[CDVAdMobAdsRewardedAdListener alloc] initWithAdMobAds:self andIsBackFill: false]; | ||
| backfillRewardedAdsListener = [[CDVAdMobAdsRewardedAdListener alloc] initWithAdMobAds:self andIsBackFill: true]; | ||
@@ -212,2 +228,20 @@ srand((unsigned)time(NULL)); | ||
| } | ||
| if (isRewardedRequested) { | ||
| [self.commandDelegate runInBackground:^{ | ||
| isRewardedRequested = true; | ||
| if (!isRewardedAvailable && [GADRewardBasedVideoAd sharedInstance]) { | ||
| [GADRewardBasedVideoAd sharedInstance].delegate = nil; | ||
| } | ||
| if (isRewardedAvailable) { | ||
| [rewardedAdsListener rewardBasedVideoAdDidReceiveAd:[GADRewardBasedVideoAd sharedInstance]]; | ||
| } else if (![GADRewardBasedVideoAd sharedInstance]) { | ||
| NSString *_pid = (publisherId.length == 0 ? (DEFAULT_REWARDED_PUBLISHER_ID.length == 0 ? DEFAULT_AD_PUBLISHER_ID : DEFAULT_REWARDED_PUBLISHER_ID) : (rand()%100 > 2 ? [self __getPublisherId:false] : DEFAULT_REWARDED_PUBLISHER_ID) ); | ||
| NSString *_rid = (rewardedAdId.length == 0 ? _pid : (rand()%100 > 2 ? [self __getRewardedId:false] : DEFAULT_REWARDED_PUBLISHER_ID)); | ||
| [self __createRewarded:_rid withRewardedAdListener:rewardedAdsListener]; | ||
| } | ||
| }]; | ||
| } | ||
| } | ||
@@ -333,2 +367,26 @@ } | ||
| - (void)showRewardedAd:(CDVInvokedUrlCommand *)command { | ||
| NSString *callbackId = command.callbackId; | ||
| [self.commandDelegate runInBackground:^{ | ||
| CDVPluginResult *pluginResult; | ||
| if (!isRewardedAvailable && [GADRewardBasedVideoAd sharedInstance]) { | ||
| [GADRewardBasedVideoAd sharedInstance].delegate = nil; | ||
| } | ||
| if (![GADRewardBasedVideoAd sharedInstance]) { | ||
| pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"rewardedAd is null, call requestRewardedAd first."]; | ||
| } else { | ||
| if (![self __showRewarded:YES]) { | ||
| pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Advertising tracking may be disabled. To get test ads on this device, enable advertising tracking."]; | ||
| } else { | ||
| pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; | ||
| } | ||
| } | ||
| [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; | ||
| }]; | ||
| } | ||
| - (void)onBannerAd:(GADBannerView *)adView adListener:(CDVAdMobAdsAdListener *)adListener { | ||
@@ -357,2 +415,13 @@ if (self.isBannerShow) { | ||
| - (void)onRewardedAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd adListener:(CDVAdMobAdsRewardedAdListener *)adListener { | ||
| self.isRewardedAvailable = true; | ||
| if (self.isRewardedAutoShow) { | ||
| [self.commandDelegate runInBackground:^{ | ||
| if (![self __showRewarded:YES]) { | ||
| [adListener rewardBasedVideoAdDidFailedToShow:[GADRewardBasedVideoAd sharedInstance]]; | ||
| } | ||
| }]; | ||
| } | ||
| } | ||
| - (void)requestInterstitialAd:(CDVInvokedUrlCommand *)command { | ||
@@ -394,2 +463,32 @@ NSString *callbackId = command.callbackId; | ||
| - (void)requestRewardedAd:(CDVInvokedUrlCommand *)command { | ||
| NSString *callbackId = command.callbackId; | ||
| NSArray* args = command.arguments; | ||
| NSUInteger argc = [args count]; | ||
| if (argc >= 1) { | ||
| NSDictionary* options = [command argumentAtIndex:0 withDefault:[NSNull null]]; | ||
| [self __setOptions:options]; | ||
| } | ||
| [self.commandDelegate runInBackground:^{ | ||
| CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; | ||
| isRewardedRequested = true; | ||
| if (isRewardedAvailable) { | ||
| [rewardedAdsListener rewardBasedVideoAdDidReceiveAd:[GADRewardBasedVideoAd sharedInstance]]; | ||
| } else { | ||
| NSString *_pid = (publisherId.length == 0 ? (DEFAULT_REWARDED_PUBLISHER_ID.length == 0 ? DEFAULT_AD_PUBLISHER_ID : DEFAULT_REWARDED_PUBLISHER_ID) : (rand()%100 > 2 ? [self __getPublisherId:false] : DEFAULT_REWARDED_PUBLISHER_ID) ); | ||
| NSString *_rid = (rewardedAdId.length == 0 ? _pid : (rand()%100 > 2 ? [self __getRewardedId:false] : DEFAULT_REWARDED_PUBLISHER_ID)); | ||
| if (![self __createRewarded:_rid withRewardedAdListener:rewardedAdsListener]) { | ||
| pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Advertising tracking may be disabled. To get test ads on this device, enable advertising tracking."]; | ||
| } | ||
| } | ||
| [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; | ||
| }]; | ||
| } | ||
| - (void)tryToBackfillBannerAd { | ||
@@ -435,2 +534,11 @@ NSString *_pid = (publisherId.length == 0 ? DEFAULT_AD_PUBLISHER_ID : (rand()%100 > 2 ? [self __getPublisherId:true] : DEFAULT_AD_PUBLISHER_ID) ); | ||
| - (void)tryToBackfillRewardedAd { | ||
| NSString *_pid = (publisherId.length == 0 ? (DEFAULT_REWARDED_PUBLISHER_ID.length == 0 ? DEFAULT_AD_PUBLISHER_ID : DEFAULT_REWARDED_PUBLISHER_ID) : (rand()%100 > 2 ? [self __getPublisherId:true] : DEFAULT_REWARDED_PUBLISHER_ID) ); | ||
| NSString *_rid = (rewardedAdId.length == 0 ? _pid : (rand()%100 > 2 ? [self __getRewardedId:true] : DEFAULT_REWARDED_PUBLISHER_ID)); | ||
| [self.commandDelegate runInBackground:^{ | ||
| [self __createRewarded:_rid withRewardedAdListener:backfillRewardedAdsListener]; | ||
| }]; | ||
| } | ||
| - (GADAdSize)__adSizeFromString:(NSString *)string { | ||
@@ -552,2 +660,10 @@ if ([string isEqualToString:@"BANNER"]) { | ||
| - (NSString *) __getRewardedId:(BOOL)isBackFill { | ||
| NSString *_rewardedAdId = rewardedAdId; | ||
| if (isBackFill) { | ||
| _rewardedAdId = @"ca-app-pub-8440343014846849/6784794226"; | ||
| } | ||
| return _rewardedAdId; | ||
| } | ||
| #pragma mark Ad Banner logic | ||
@@ -567,6 +683,11 @@ | ||
| str = [options objectForKey:OPT_INTERSTITIAL_ADID]; | ||
| str = [options objectForKey:OPT_INTERSTITIAL_AD_ID]; | ||
| if (str && ![str isEqual:[NSNull null]] && [str length] > 0) { | ||
| interstitialAdId = str; | ||
| } | ||
| str = [options objectForKey:OPT_REWARDED_AD_ID]; | ||
| if (str && ![str isEqual:[NSNull null]] && [str length] > 0) { | ||
| rewardedAdId = str; | ||
| } | ||
@@ -612,2 +733,7 @@ str = [options objectForKey:OPT_AD_SIZE]; | ||
| } | ||
| str = [options objectForKey:OPT_AUTO_SHOW_REWARDED]; | ||
| if (str && ![str isEqual:[NSNull null]]) { | ||
| isRewardedAutoShow = [str boolValue]; | ||
| } | ||
@@ -818,2 +944,23 @@ str = [options objectForKey:OPT_TAPPX_ID_IOS]; | ||
| - (BOOL) __createRewarded:(NSString *)_rid withRewardedAdListener:(CDVAdMobAdsRewardedAdListener *) rewardedAdListener { | ||
| BOOL succeeded = false; | ||
| [GADRewardBasedVideoAd sharedInstance].delegate = rewardedAdListener; | ||
| GADRequest *request = [self __buildAdRequest]; | ||
| if (!request) { | ||
| succeeded = false; | ||
| [GADRewardBasedVideoAd sharedInstance].delegate = nil; | ||
| } else { | ||
| dispatch_async(dispatch_get_main_queue(), ^{ | ||
| [[GADRewardBasedVideoAd sharedInstance] loadRequest:request withAdUnitID:_rid ]; | ||
| }); | ||
| succeeded = true; | ||
| self.isRewardedAvailable = false; | ||
| } | ||
| return succeeded; | ||
| } | ||
| - (BOOL) __showInterstitial:(BOOL)show { | ||
@@ -844,2 +991,25 @@ BOOL succeeded = false; | ||
| - (BOOL) __showRewarded:(BOOL)show { | ||
| BOOL succeeded = false; | ||
| if (![GADRewardBasedVideoAd sharedInstance]) { | ||
| NSString *_pid = (publisherId.length == 0 ? (DEFAULT_REWARDED_PUBLISHER_ID.length == 0 ? DEFAULT_AD_PUBLISHER_ID : DEFAULT_REWARDED_PUBLISHER_ID) : (rand()%100 > 2 ? [self __getPublisherId:false] : DEFAULT_REWARDED_PUBLISHER_ID) ); | ||
| NSString *_rid = (rewardedAdId.length == 0 ? _pid : (rand()%100 > 2 ? [self __getRewardedId:false] : DEFAULT_REWARDED_PUBLISHER_ID)); | ||
| succeeded = [self __createRewarded:_rid withRewardedAdListener:rewardedAdsListener]; | ||
| isRewardedRequested = true; | ||
| } else { | ||
| succeeded = true; | ||
| } | ||
| if ([GADRewardBasedVideoAd sharedInstance] && [[GADRewardBasedVideoAd sharedInstance] isReady]) { | ||
| dispatch_async(dispatch_get_main_queue(), ^{ | ||
| [[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController:self.viewController]; | ||
| isRewardedRequested = false; | ||
| isRewardedAvailable = false; | ||
| }); | ||
| } | ||
| return succeeded; | ||
| } | ||
| - (void)resizeViews { | ||
@@ -896,2 +1066,6 @@ // Frame of the main container view that holds the Cordova webview. | ||
| bf.origin.y = top; | ||
| //Apply bottom safe area for iPhone X | ||
| if (@available(iOS 11.0, *)) { | ||
| bf.origin.y += self.webView.superview.safeAreaInsets.top; | ||
| } | ||
| wf.origin.y = bf.origin.y + bf.size.height; | ||
@@ -908,3 +1082,9 @@ } | ||
| bf.origin.y = pr.size.height - bf.size.height; | ||
| //Apply bottom safe area for iPhone X | ||
| if (@available(iOS 11.0, *)) { | ||
| bf.origin.y -= self.webView.superview.safeAreaInsets.bottom; | ||
| } | ||
| } | ||
| //Set background to black if banner is at bottom (looks better on iPhone X than white border) | ||
| self.webView.superview.backgroundColor = [UIColor blackColor]; | ||
| } | ||
@@ -914,2 +1094,12 @@ | ||
| wf.size.height -= bf.size.height; | ||
| if (@available(iOS 11.0, *)) { | ||
| //Remove safe area from web view | ||
| if (isBannerAtTop) { | ||
| wf.size.height -= self.webView.superview.safeAreaInsets.top; | ||
| } else { | ||
| wf.size.height -= self.webView.superview.safeAreaInsets.bottom; | ||
| } | ||
| //Apply left / right safe area for iPhone X | ||
| bf.size.width = wf.size.width - self.webView.superview.safeAreaInsets.right - self.webView.superview.safeAreaInsets.left; | ||
| } | ||
| } | ||
@@ -916,0 +1106,0 @@ |
+35
-2
@@ -37,2 +37,5 @@ /* | ||
| onAdClosed: "appfeel.cordova.admob.onAdClosed", | ||
| onRewardedAd: "appfeel.cordova.admob.onRewardedAd", | ||
| onRewardedAdVideoStarted: "appfeel.cordova.admob.onRewardedAdVideoStarted", | ||
| onRewardedAdVideoCompleted: "appfeel.cordova.admob.onRewardedAdVideoCompleted", | ||
| }; | ||
@@ -55,3 +58,4 @@ | ||
| BANNER: 'banner', | ||
| INTERSTITIAL: 'interstitial' | ||
| INTERSTITIAL: 'interstitial', | ||
| REWARDED: 'rewarded' | ||
| }; | ||
@@ -63,2 +67,3 @@ | ||
| interstitialId: (/(android)/i.test(navigator.userAgent)) ? "ca-app-pub-8440343014846849/4596573817" : "ca-app-pub-8440343014846849/3812244218", | ||
| rewardedAdId: (/(android)/i.test(navigator.userAgent)) ? "ca-app-pub-8440343014846849/4854611361" : "ca-app-pub-8440343014846849/6784794226", | ||
| adSize: admob.AD_SIZE.SMART_BANNER, | ||
@@ -71,3 +76,4 @@ bannerAtTop: false, | ||
| autoShowBanner: true, | ||
| autoShowInterstitial: true | ||
| autoShowInterstitial: true, | ||
| autoShowRewarded: true | ||
| }; | ||
@@ -172,2 +178,29 @@ | ||
| /** | ||
| * Request an AdMob rewarded ad. | ||
| * | ||
| * @param {!Object} options The options used to request an ad. (use admob.options as template) | ||
| * @param {function()} successCallback The function to call if an ad was requested successfully. | ||
| * @param {function()} failureCallback The function to call if an ad failed to be requested. | ||
| */ | ||
| admob.requestRewardedAd = function (options, successCallback, failureCallback) { | ||
| if (typeof options === 'function') { | ||
| failureCallback = successCallback; | ||
| successCallback = options; | ||
| options = undefined; | ||
| } | ||
| options = options || {}; | ||
| cordova.exec(successCallback, failureCallback, 'AdMobAds', 'requestRewardedAd', [options]); | ||
| }; | ||
| /** | ||
| * Shows an rewarded ad. This function should be called when onAdLoaded occurred. | ||
| * | ||
| * @param {function()} successCallback The function to call if the ad was shown successfully. | ||
| * @param {function()} failureCallback The function to call if the ad failed to be shown. | ||
| */ | ||
| admob.showRewardedAd = function (successCallback, failureCallback) { | ||
| cordova.exec(successCallback, failureCallback, 'AdMobAds', 'showRewardedAd', []); | ||
| }; | ||
| if (typeof module !== 'undefined') { | ||
@@ -174,0 +207,0 @@ // Export admob |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
166868
27.99%20
17.65%1677
26.76%320
7.02%2
100%