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

Interstitial ad fails to show in Flutter modules. "The provided view controller is already presenting another view controller." [iOS] #700

Closed
rckrd-proguitar opened this issue Nov 16, 2022 · 16 comments
Labels
bug Something isn't working e3-weeks Effort: < 4 weeks flutter Issues related to flutter interstitial ad Issues related to Interstitial Ad p2-medium platform-ios iOS applications specifically

Comments

@rckrd-proguitar
Copy link

rckrd-proguitar commented Nov 16, 2022

Plugin Version

2.3.0

Steps to Reproduce

  1. Run flutter create bug -t module.
  2. Update the files as follows: Show an Interstitial ad
  3. Create a host app: https://docs.flutter.dev/development/add-to-app/ios/project-setup
  4. Add a flutter screen: https://docs.flutter.dev/development/add-to-app/ios/add-flutter-screen?tab=initial-route-without-pre-warming-objective-c-tab
  5. Open the flutter screen and then open the interstitial ad in flutter

Expected results: The Interstitial ad is shown in fullscreen.

Actual results: The view fails to show. Error message: "The provided view controller is already presenting another view controller."

The view controller used to present to interstitial ad view is not the "Flutter view controller" when flutter is running in a host app.
The viewcontroller used is the rootviewcontroller of the host app, i.e the main view of the host app.

https://github.com/googleads/googleads-mobile-flutter/blob/main/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m#L196

Possible solution:
Is there any reason not to use the view controller that is on top of the stack? When a host app opens flutter it's convenient to keep the rootviewcontroller as the main native/host VC so it is easy to navigate back to the host app from flutter.

Logs

FullScreenContentCallback.onAdFailedToShowFullScreenContent: "The provided view controller is already presenting another view controller."

flutter doctor -v:

[✓] Flutter (Channel stable, 3.3.8, on macOS 12.6 21G115 darwin-x64, locale en-SE)
• Flutter version 3.3.8 on channel stable at /Users/rickard/Dev/flutter/sdk
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 52b3dc25f6 (7 days ago), 2022-11-09 12:09:26 +0800
• Engine revision 857bd6b74c
• Dart version 2.18.4
• DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/rickard/Dev/Android/sdk
• Platform android-31, build-tools 31.0.0
• ANDROID_HOME = /Users/rickard/Dev/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14B47b
• CocoaPods version 1.11.3

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.73.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.52.0

[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 12.6 21G115 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
• All required HTTP hosts are available

• No issues found!

@huycozy huycozy added the in triage Issue currently being evaluated label Nov 16, 2022
@huycozy
Copy link
Collaborator

huycozy commented Nov 16, 2022

Hi @rckrd-proguitar
Please provide a completed and minimal reproducible code sample so that we may verify this. In this case, the issue relates to native side, it will be better if you can push the sample code into a Github repository and make it public.

Also, please provide the output of flutter doctor -v as well. Thank you!

@huycozy huycozy added the feedback required Further information is requested label Nov 16, 2022
@rckrd-proguitar
Copy link
Author

rckrd-proguitar commented Nov 16, 2022

Here you go @huycozy : https://github.com/rckrd-proguitar/googleads-mobile-flutter-issue-700

The example generates the following log when the interstitial ad tries to present itself:

flutter: Instance of 'InterstitialAd' onAdFailedToShowFullScreenContent: AdError(code: 17, domain: com.google.admob, message: The provided view controller is already presenting another view controller.)

You find the output of flutter doctor -v under "Logs" above.

@github-actions github-actions bot removed the feedback required Further information is requested label Nov 16, 2022
@rckrd-proguitar
Copy link
Author

rckrd-proguitar commented Nov 17, 2022

If there is no other workaround or error on my part, the following could maybe be a solution to find the view controller on top.

- (UIViewController *)rootController {
  UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController;
  if(rootViewController.presentedViewController != nil){
    return rootViewController.presentedViewController;
  }
  return rootViewController;
}

@huycozy
Copy link
Collaborator

huycozy commented Nov 21, 2022

@rckrd-proguitar Sorry for replying late. I can reproduce this issue with provided sample code at #700 (comment).

Labeling this issue for further investigation from the team. Thanks!

Demo video
Screen.Recording.2022-11-21.at.12.41.32.mov
Log
2022-11-21 12:41:47.641029+0700 googleads-mobile-issue-700[36290:1158896] flutter: Instance of 'InterstitialAd' onAdFailedToShowFullScreenContent: AdError(code: 17, domain: com.google.admob, message: The provided view controller is already presenting another view controller.)
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.3.8, on macOS 13.0 22A380 darwin-x64, locale en-VN)
    • Flutter version 3.3.8 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 52b3dc25f6 (23 hours ago), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2022.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 70.0.5
    • Dart plugin version 222.4167.21

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.73.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • 332079AF-E895-4685-910E-7B1E18B0C6B8 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-0 (simulator)
    • macOS (desktop)            • macos                                • darwin-x64     • macOS 13.0 22A380 darwin-x64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
[!] Flutter (Channel master, 3.6.0-6.0.pre.29, on macOS 13.0 22A380 darwin-x64, locale en-VN)
    • Flutter version 3.6.0-6.0.pre.29 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ee9bc784b5 (2 hours ago), 2022-11-20 19:32:24 -0500
    • Engine revision 271461837e
    • Dart version 2.19.0 (build 2.19.0-406.0.dev)
    • DevTools version 2.19.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2022.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 70.0.5
    • Dart plugin version 222.4167.21

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • SM T225 (mobile) • R9JT3004VRJ • android-arm64  • Android 12 (API 31)
    • macOS (desktop)  • macos       • darwin-x64     • macOS 13.0 22A380 darwin-x64
    • Chrome (web)     • chrome      • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

@huycozy huycozy added bug Something isn't working p1-high e3-weeks Effort: < 4 weeks platform-ios iOS applications specifically interstitial ad Issues related to Interstitial Ad flutter Issues related to flutter and removed in triage Issue currently being evaluated labels Nov 21, 2022
jjliu15 added a commit to jjliu15/googleads-mobile-flutter-1 that referenced this issue Apr 13, 2023
@khizar1556
Copy link

khizar1556 commented Oct 15, 2023

@jjliu15 I am facing this issue in version 3.1.0 but if i downgrade it to 2.4.0 its working fine
Instance of 'InterstitialAd' onAdFailedToShowFullScreenContent1: AdError(code: 17, domain: com.google.admob, message: The provided view controller is not being presented.)

Anyone Resolve this?

@FranciscoVenegas
Copy link

Hello
I am receiving the same error in version 3.1.0 (I cannot downgrade due to compatibility issues).
In my case the first interstitial displays fine, however the 2nd one fails. Then the 3rd works fine, then the 4th fails, and so on.

@renis1235
Copy link

I also have this issue.
It doesn't seem to be solved.

@aruhant
Copy link

aruhant commented Jan 25, 2024

Check if you are accidentally disposing the ad at a wrong place.
The best practice for when to call dispose() is in the FullScreenContentCallback.onAdDismissedFullScreenContent and FullScreenContentCallback.onAdFailedToShowFullScreenContent callbacks.

@renis1235
Copy link

That is exactly when I do that and it still does not work.
Only when I downgrade...

@10peter10
Copy link

I am still getting "The provided view controller is not being presented." as described in previous post.. please is there any solution for this ? It only works as expected at version 2.4.0 .. but at this version CMP is not implemented, which we need in our app. Please let us know as soon as problem is solved.

@dominikhalvonik
Copy link

Same here, the problem is definetly not solved.

@Gilianp
Copy link

Gilianp commented May 15, 2024

Same here, multiple occurrences!!

@turbobuilt
Copy link

This happens the first time I show the ad. But I moved the code to an external file, and that's when it all started happening.

@SuYueQiuLiang
Copy link

Mark,same question in newest sdk version 5.1.0, anyone has some way to fix it?

@malandr2
Copy link
Collaborator

I have re-opened the case and have shared with engineering to take another look

@malandr2
Copy link
Collaborator

This has been resolved with #1153 and will be included in the next google_mobile_ads plugin release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working e3-weeks Effort: < 4 weeks flutter Issues related to flutter interstitial ad Issues related to Interstitial Ad p2-medium platform-ios iOS applications specifically
Projects
None yet
Development

No branches or pull requests