invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.68k stars 2.21k forks source link

[🐛] [admob / unknown] The provided view controller is already presenting another view controller #4631

Closed daheeahn closed 3 years ago

daheeahn commented 3 years ago

Version

react-native: 0.61.5 @react-native-firebase/app: 8.4.1 @react-native-firebase/admob: 7.6.2

Issue

In my app, there are two advertisements with different ids. Ad 1 is displayed well, but when I try to load Ad 2, this error is displayed. There seems to be a related issue already, but has it been fixed yet? (Related Issue: https://github.com/invertase/react-native-firebase/issues/2292)

My Code

import admob, { RewardedAd, RewardedAdEventType, AdEventType, MaxAdContentRating } from '@react-native-firebase/admob';

  const getAds = async () => {
    try {
      await admob().setRequestConfiguration({
        maxAdContentRating: MaxAdContentRating.G,
        tagForChildDirectedTreatment: true,
      });

      const ADS_ID = getAdId(/* my id*/);

      const rewarded = RewardedAd.createForAdRequest(ADS_ID, {
        requestNonPersonalizedAdsOnly: true,
      });

      rewarded.onAdEvent((type, error, reward) => {
        if (error) {
        }
        if (type === RewardedAdEventType.LOADED) {
          rewarded.show();
        }
      });
      rewarded.load();
    } catch (e) {
    }
  };

ios/Podfile:

platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'roubit' do
  # Pods for roubit
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
  pod 'Firebase/Analytics'
  pod 'Firebase/Crashlytics'
  # for react-native-pie-chart (이걸 안하면 no component found for view with name ARTSahpe 에러가 남.)
  # pod 'React-ART', :path => '../node_modules/react-native/Libraries/ART'
  pod 'CodePush', :path => '../node_modules/react-native-code-push'

  # facebook
  pod 'FacebookSDK'
  pod 'FacebookSDK/LoginKit'
  pod 'FacebookSDK/ShareKit'
  pod 'FacebookSDK/PlacesKit'
  pod 'FBSDKMarketingKit'
  pod 'FBSDKMessengerShareKit'

  target 'roubitTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

target 'roubit-tvOS' do
  # Pods for roubit-tvOS

  target 'roubit-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

end
mikehardy commented 3 years ago

Hi there!

Your versions are out of date, please only file issues against current versions (v10.1.0 here, v7.1.0 of underlying firebase-ios-sdk along with up to date MobileAds pod)

I'm not sure how this is a react-native-firebase issue? The related issue was in react-native, and you don't appear to be using 0.63.3 there so you may be running into a bug already fixed

You mention Ad1 and Ad2 there is no notation of same in the example code

Please post a reproduction based solely on a clean up to date repro like that from https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh and an App.js that is self-contained and shows the problem and we may investigate further

daheeahn commented 3 years ago

Hi ! Then, this issue could be version related. After fixing the version, I'll test it and come back. Thanks 😊

TaylorDale commented 3 years ago

Also getting this issue when trying to use Interstitials and Rewarded at the same time. Setup is something like this:

const interstitial = InterstitialAd.createForAdRequest(intId);
interstitial.load();
const rewarded = RewardedAd.createForAdRequest(rewardId);
rewarded.load();

export default () => {
    return <>
             <Button onPress={interstitial.show}><Text>Int.</Text></Button>
             <Button onPress={rewarded.show}><Text>Reward</Text></Button>
    </>      
}

Without ever having touched the interstitial button, the rewarded button will fail to show and produce the following error in the callback:

[Error: [admob/unknown] The provided view controller is already presenting another view controller.]

Podfile:

 - Firebase/AdMob (7.1.0):
    - Firebase/CoreOnly
    - Google-Mobile-Ads-SDK (~> 7.66)

RN Version 0.63.3

mikehardy commented 3 years ago

Interesting - we're on firebase ios sdk 7.2.0 now underlying (working on testing it for release now - seems fine and you can override it to see) - but I don't think that will affect things

You might dive into node_modules and instrument the admob code with extra logging around the calls in question to untangle it. I don't use admob personally but if you can find the root cause for this and post a PR I'd happily work with you to get it merged and released to save yourself and any future explorers the hassle

TaylorDale commented 3 years ago

This seemed to be a little more related to my code:

I was asking the user if they wanted to watch a rewarded ad with a RN Modal, and they did not like being up at the same time.

I set the presence of the modal to true or false using router state, so calling:

dismiss();
showAd();

Simultaneously did not cause the modal view to be dismissed in time for the rewarded ad to show.

I use setTimeout with a small delay to bypass this... not the best fix but it will do for now until I restructure.

Cetger commented 3 years ago

I have a project that includes the same code. There isn't any error in android but I got this issue on iOS. I'm using Modal to display "open rewarded add" button. This issue because of react-native. You can fix your issue with this. Change Modal to view and render the view by if(isVisible) condition. This isVisible state is as the same as modal's.