Loading Multiple Google Interstitial Ads Makes App Crash

Loading multiple google interstitial ads makes app crash

This is not how you go about using AdMob's interstitials. You should only be creating one var to store your interstitial in.

Create the interstitial and request an ad. Once you've presented the ad and the ad has been dismissed you request another ad. Listen to its delegate methods to find out when its been dismissed.

For example:

import UIKit
import GoogleMobileAds // Import AdMob

class ViewController: UIViewController, GADInterstitialDelegate { // Delegate

// Create variable
var myInterstitial: GADInterstitial!

override func viewDidLoad() {
super.viewDidLoad()
loadAd() // Load the ad
}

func loadAd() {
myInterstitial = GADInterstitial(adUnitID: "your_admob_id") // Create ad
myInterstitial.delegate = self // Set delegate
myInterstitial.loadRequest(GADRequest()) // Request ad
}

func showAd() { // Call this func when you want to show an ad
if myInterstitial.isReady { // Check to see if interstitial has an ad and is ready to be displayed
myInterstitial.presentFromRootViewController(self) // Present the ad
}
else {
print("Ad not ready")
}
}

func interstitialDidDismissScreen(ad: GADInterstitial!) {
// The ad has been dismissed from the screen by the user
// Request a new ad for the next time you want to show one
loadAd() // Load a new ad
}

For more information refer to Google's docs, AdMob for iOS.

My app crashes when the Admob ad is displayed (Interstitial Ad)

I found the answer myself!

I tried to use a different version and it works every time

Flutter App Crashes when Trying to Load Interstitial Ad

I have solved it.

1.add com.google.android.gms:play-services-ads in android/app/build.gradle
dependencies {
...

implementation 'com.google.android.gms:play-services-ads:7.5.0'

}

2.add multidex in android/app/build.gradle
dependencies {
...

implementation 'com.android.support:multidex:1.0.3'

}


  1. in the defaultConfig enable multidex
    defaultConfig {
    ...

    multiDexEnabled true

...
}

App is crashing while calling interstitialAd.load() method in React-Native

I maintain react-native-firebase and maybe I can explain why this happened, as well as the fix.

@react-native-firebase/admob will not crash if used by itself, with InterstitialAds

However, firebase-android-sdk and the admob just issued a breaking change release (v27 for firebase-android-sdk, v20 for admob) that moves InterstitialAd package names and if you have another admob dependency where the gradle dependency was specified with a version of +, that allows the breaking change version to leak through and break your app.

So pinning the dependency in your build.gradle as others have commented will fix you:

implementation("com.google.android.gms:play-services-ads:19.8.0") { force = true; }

Full details here: https://github.com/invertase/react-native-firebase/issues/5127

react-native-firebase (including the admob module) v11.3.1 is releasing now with contents of this PR to fix things: https://github.com/invertase/react-native-firebase/pull/5189

Good luck with your projects



Related Topics



Leave a reply



Submit