react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

🔥 Admob - rewardedAd.load() not working the second time

Open ilyakar opened this issue 6 years ago • 8 comments

Issue

rewardedAd.load() does not load ad on the second time. Everything works fine with the loading, showing, callbacks for the first ad shown, when I then do a rewardedAd.load() again to load another ad, nothing happens. No errors, no callbacks. Then obviously calling rewardedAd.show() rusults in a admob/not-ready error.

This problem occurs in admob/firebase versions 6.2.0 and 6.3.1

    if(environment == 'development'){
      rewardedAd = RewardedAd.createForAdRequest(TestIds.REWARDED)
    }
    else if(environment == 'production'){
      rewardedAd = RewardedAd.createForAdRequest(settings.adsUnitIds.ios.real)
    }
    // --

    rewardedAd.onAdEvent((type, error, reward) => {
      console.log('onAdEvent, type:', type, ', error:', error)
      if(type === RewardedAdEventType.LOADED){
        dispatch({ type: 'AD_LOADED' })
      }

      if(type == 'closed'){ // RewardedAdEventType.CLOSED isn't defined (probably bug), so just made it "closed", which works
        console.log('ad closed, rewarded:', rewarded)
        if(rewarded == true){
          if(!doubleReward){
            dispatch(rewardCoins(settings.coins.ad, 'watched-ad'))
          }
          else {
            dispatch(rewardCoins(settings.coins.ad*2, 'watched-ad'))
          }
          rewarded = false
        }
        dispatch({ type: 'AD_CLOSED', rewarded: rewarded })

        if(showEnded) showEnded()

        setTimeout(() => { // Cannot reproduce bug where re-request of ad isn't available so adding this just in case
          console.log('Start ad re-request')
          console.log('Do we have rewardedAd variable? :', rewardedAd)
          rewardedAd.load()
        }, 200)
      }

      if(type === RewardedAdEventType.EARNED_REWARD){
        console.log('earned reward!')
        dispatch({ type: 'AD_REWARDED' })
        rewarded = true
      }
      
      if(type === RewardedAdEventType.ERROR){
        console.info('Some error with ad:', error)
      }
    })

    rewardedAd.load()

Project Files

iOS

Click To Expand

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'Einee' do

  # General Pods
  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'


  # Einee Pods
  pod 'react-native-onesignal', :path => '../node_modules/react-native-onesignal'

  pod 'react-native-blur', :path => '../node_modules/@react-native-community/blur'

  pod 'RNSound', :path => '../node_modules/react-native-sound'

  pod 'react-native-mail', :path => '../node_modules/react-native-mail'

  pod 'RNRate', :path => '../node_modules/react-native-rate'


  pod 'react-native-amplitude-analytics', :path => '../node_modules/react-native-amplitude-analytics'

  pod 'RNFastImage', :path => '../node_modules/react-native-fast-image'

  pod 'RNReactNativeHapticFeedback', :path => '../node_modules/react-native-haptic-feedback'

  pod 'RNDevMenu', :path => '../node_modules/react-native-dev-menu'

  pod 'RCTRestart', :path => '../node_modules/react-native-restart/ios'

  pod 'RNIap', :path => '../node_modules/react-native-iap'

  pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'


  pod 'RNShare', :path => '../node_modules/react-native-share'



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

  use_native_modules!
end

AppDelegate.m:

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Bolts/Bolts.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <React/RCTLinkingManager.h>
#import "IAPPromotionObserver.h"
#import <Firebase.h>

@implementation AppDelegate

- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }
  
  // Uncomment this line to use the test key instead of the live one.
  NSURL *jsCodeLocation;

  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"Einee"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
  
  [IAPPromotionObserver startObserving];
  
  [[FBSDKApplicationDelegate sharedInstance] application:application
                           didFinishLaunchingWithOptions:launchOptions];
  
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  
  if (launchOptions[UIApplicationLaunchOptionsURLKey] == nil) {
    [FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error) {
      if (error) {
        NSLog(@"Received error while fetching deferred app link %@", error);
      }
      if (url) {
        [[UIApplication sharedApplication] openURL:url];
      }
    }];
  }
  
  return YES;
}

// Respond to URI scheme links
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  // Facebook scheme click detect
  return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
    return [RCTLinkingManager application:application openURL:url options:options];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
    return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}

@end


Android

Click To Expand

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 System:
    OS: macOS 10.15.3
    CPU: (8) x64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
    Memory: 30.20 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 13.6.0 - ~/.nvm/versions/node/v13.6.0/bin/node
    Yarn: 1.16.0 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v13.6.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
  IDEs:
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: ^0.61.5 => 0.61.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7
  • Platform that you're experiencing the issue on:
    • [x] iOS
    • [ ] Android
    • [x] iOS but have not tested behavior on Android
    • [ ] Android but have not tested behavior on iOS
    • [ ] Both
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/N


Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

ilyakar avatar Feb 09 '20 14:02 ilyakar

@ilyakar Thanks for raising this issue, we fixed this bug in this PR: #3190. Should come out in the next release 👍

russellwheatley avatar Feb 10 '20 18:02 russellwheatley

Wonderful. Thank you!

Sent from my iPhone

On 10 Feb 2020, at 18:49, Russell Wheatley [email protected] wrote:

 @ilyakar Thanks for raising this issue, we fixed this bug in this PR: #3190. Should come out in the next release 👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

ilyakar avatar Feb 10 '20 19:02 ilyakar

Hi, have same issue on 7.1.2. The first reward video is OK,but I can't load second reward.

RatFou avatar Jun 01 '20 20:06 RatFou

I am experiencing the same issue on version 7.1.3 for both the rewarded and InterstitialAds

enosh94 avatar Jun 06 '20 11:06 enosh94

Still experiencing this issue in 7.3.3

ealmiladi avatar Jul 30 '20 13:07 ealmiladi

I understand android says that you have to reload the ad, recreate it or load it again.

Only-IceSoul avatar Nov 23 '20 15:11 Only-IceSoul

not working till now. I am calling the load() right after the RewardedAdEventType.EARNED_REWARD event is fired

renzified avatar Dec 20 '20 12:12 renzified

@thekingrenz23 this is a closed issue. If you have a problem please reproduce the issue on current versions, ideally from a clean app built with https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh and a standalone App.js that reproduces the problem, then we can investigate

Comments on closed issues - especially those that provide no helpful information to reproduce - receive no attention, sorry

mikehardy avatar Dec 20 '20 14:12 mikehardy