invertase / react-native-google-mobile-ads

React Native Google Mobile Ads enables you to monetize your app with AdMob.
https://docs.page/invertase/react-native-google-mobile-ads
Other
686 stars 139 forks source link

[๐Ÿ›] Can't load Rewarded Interstitial & Rewarded Ads but it's all good for the others, plz any help #293

Closed bilal-prog closed 1 year ago

bilal-prog commented 1 year ago

What happened?

import React, {useEffect, useState} from 'react'; import { View, FlatList, Text, TouchableOpacity, BackHandler, } from 'react-native'; import {Actions} from 'react-native-router-flux'; import AutoHeightImage from 'react-native-auto-height-image'; import { RewardedAd, RewardedAdEventType, TestIds, } from 'react-native-google-mobile-ads'; import styles from './style'; import Footer from 'components/Footer'; import Item from './Item';

const Notifications = props => { const {fetching} = props.notifications; const params = {top: 10, first: 0}; const [state, setState] = useState({ data: [], filter: 'all', query: '', countLocal: 0, load: false, });

const adUnitId = TestIds.REWARDED;

const rewarded = RewardedAd.createForAdRequest(adUnitId, { requestNonPersonalizedAdsOnly: true, keywords: ['fashion', 'clothing'], });

useEffect(() => { const willBlurListener = props.navigation.addListener('didFocus', () => { const {count} = props.notifications; props.actions.setCountNotificatons(count); onRefresh(); });

const sub = BackHandler.addEventListener(
  'hardwareBackPress',
  handleBackHandler,
);
const unsubscribeLoaded = rewarded.addAdEventListener(
  RewardedAdEventType.LOADED,
  () => {
    setState({...state, load: true});
    rewarded.show();
    console.log(
      '-------------------=========loaded==========---------------------',
    );
  },
);
const unsubscribeEarned = rewarded.addAdEventListener(
  RewardedAdEventType.EARNED_REWARD,
  reward => {
    console.log('User earned reward of ', reward);
    console.log(
      '-------------------=========earned==========---------------------',
    );
  },
);
rewarded.load();

return () => {
  sub.remove();
  willBlurListener.remove();
  unsubscribeEarned();
  unsubscribeLoaded();
};

}, []);

const handleBackHandler = () => { try { Actions.pop(); return true; } catch { return false; } };

return (

); };

export default Notifications; `

Platforms

Android and iOS

React Native Info

"react-native": "0.61.5"

Are your using Typescript?

package.json

"react-native-google-mobile-ads": "^8.1.2"

app.json

{}

ios/Podfile

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

## Add Use modular headders globally
use_modular_headers!

target 'xxxxx' do
  # Pods for Prim
  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'

  # disable use modular headers for Double Conversion, Glog and Folly:

  pod "DoubleConversion", :podspec => "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec", :modular_headers => false
  pod "glog", :podspec => "../node_modules/react-native/third-party-podspecs/glog.podspec", :modular_headers => false
  pod "Folly", :podspec => "../node_modules/react-native/third-party-podspecs/Folly.podspec", :modular_headers => false

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'Permission-LocationAccuracy', :path => "../node_modules/react-native-permissions/ios/LocationAccuracy"
  pod 'Permission-LocationAlways', :path => "../node_modules/react-native-permissions/ios/LocationAlways"
  pod 'Permission-LocationWhenInUse', :path => "../node_modules/react-native-permissions/ios/LocationWhenInUse"
  pod 'Firebase/Analytics'
  pod 'Google-Mobile-Ads-SDK'
  target 'xxxxTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

target 'xxxxx-tvOS' do
  # Pods for xxxx-tvOS

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

end

post_install do |installer|
  ## Fix for XCode 12.5
      find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
      "_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")
      find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
      "RCTBridgeModuleNameForClass(module))", "RCTBridgeModuleNameForClass(Class(module)))")
  end

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
          puts "Fix: " + name
          File.open(name, "w") { |file| file.puts replace }
          STDOUT.flush
      end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end

android/build.gradle

classpath("com.android.tools.build:gradle:4.2.2") 
classpath 'com.google.gms:google-services:4.3.3'

android/app/build.gradle

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

android/settings.gradle

rootProject.name = 'Xxxx'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
  package="com.XX.XXXX">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@drawable/icon"
      android:allowBackup="false"
      android:requestLegacyExternalStorage="true"
      android:theme="@style/AppTheme">
      <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
      <meta-data
      android:name="com.google.android.geo.API_KEY"
      android:value="Xxxxxxxxxxx"/>
      <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxx~yyyyyyyy"
            tools:replace="android:value"/>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"
        android:launchMode="singleTop"
        android:exported="true"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="xxxxxx" android:host="app" /> <!--scheme should be defined-->
            <data android:scheme="xxxxxxx" android:host="login" /> <!--scheme should be defined-->
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
      <uses-library
        android:name="org.apache.http.legacy"
        android:required="false"
     /> <!--For map to open on new android version -->
    </application>

</manifest>
mikehardy commented 1 year ago

That looks like a Podfile from an unsupported version of react-native - I'm not used to seeing all that stuff in there. Does this still reproduce on current versions ?

https://github.com/reactwg/react-native-releases/#releases-support-policy

mikehardy commented 1 year ago

Also you don't mention make / model of the device you are testing on, plus this line is not necessary I think, the module should bring it in for you:

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

bilal-prog commented 1 year ago

I'm testing on android

bilal-prog commented 1 year ago

Yes you are right my react native version is unsupported

mikehardy commented 1 year ago

@panktiszluck a second threadjack! You are cross-posting this. Please do not do that. Also, your react-native is old enough it is out of support https://github.com/reactwg/react-native-releases#releases-support-policy

little-steps commented 1 year ago

@bilal-prog is your reward ad is working?

github-actions[bot] commented 1 year ago

Hello ๐Ÿ‘‹, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

little-steps commented 1 year ago

RewardedAd.show() The requested RewardedAd has not loaded and could not be shown.[๐Ÿ›] Bug Report Title - CHANGE ME #291 this above issue is still not working rewardedAd are not displaying

Ammark321 commented 1 year ago

RewardedAd.show() The requested RewardedAd has not loaded and could not be shown.[๐Ÿ›] Bug Report Title - CHANGE ME #291 this above issue is still not working rewardedAd are not displaying

i am facing same issue too any luck?

github-actions[bot] commented 1 year ago

Hello ๐Ÿ‘‹, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

dprajapati1179 commented 1 year ago

Anyone can please share the code for showing multiple ads with click of a button I am having the same issue first ad lodes perfectly but other ads not loading and while calling shows my app is crashing