【问题标题】:Admob failed to load with error "at nativeToJSError" - React NativeAdmob 无法加载错误“at nativeToJSError” - React Native
【发布时间】:2019-05-01 15:56:00
【问题描述】:

问题

我的应用程序的产品版本中当前正在运行一些应用程序,但由于某种原因没有对我的代码进行任何更改,我现在在 Android 上测试我的 React Native 时收到以下错误。我在我电脑上的安卓模拟器和连接到我电脑的安卓设备上都试过了。

在今天之前,它在 iOS 上完美运行,在 Android 上完美运行。

我在几周前启用了我的广告,所以这不是库存不足的问题,如果是这种情况,我的调试器中会显示为库存不足

如果有人有建议那就太好了!这使我无法为我的用户推送重要更新。

错误

result     at nativeToJSError (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:105783:17)
    at AdMobComponent._this.onBannerEvent (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:106684:64)
    at Object.invokeGuardedCallbackImpl (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:7899:16)
    at invokeGuardedCallback (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:7990:37)
    at invokeGuardedCallbackAndCatchFirstError (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:7994:31)
    at executeDispatch (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8188:9)
    at executeDispatchesInOrder (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8208:11)
    at executeDispatchesAndRelease (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8303:11)
    at executeDispatchesAndReleaseTopLevel (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8312:16)
    at forEachAccumulated (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8295:14)

错误传回的参数

Arguments [callee: ƒ, Symbol(Symbol.iterator): ƒ]
 callee: ƒ render()
  arguments: null
  caller: null
  length: 0
  name: "render"
  prototype: {constructor: ƒ}
  __proto__: ƒ ()
  [[FunctionLocation]]: Admob.js:33
  [[Scopes]]: Scopes[3]
  length: 0
 Symbol(Symbol.iterator): ƒ values()
  arguments: [Exception: TypeError: 'caller', 'callee', and  'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:2:14)]
  caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:2:14)]
  length: 0
  name: "values"
  __proto__: ƒ ()
  [[Scopes]]: Scopes[0]
  __proto__: Object

Admob 组件代码 该代码与 react-native 应用程序中的代码完全相同,我所做的唯一更改是删除了应用程序和单元 ID。我已经检查以确保它们是正确的。

  import React, {Component} from 'react';
    import {
    StyleSheet,
    View,
    Text,
    Dimensions,
  Image,
  TouchableWithoutFeedback
} from 'react-native';

import firebase from 'react-native-firebase';


const Analytics = firebase.analytics()
const Admob = firebase.admob()
const Banner = firebase.admob.Banner;
const AdRequest = firebase.admob.AdRequest;
const request = new AdRequest().addTestDevice()


export default class AdmobComponent extends React.Component{

  constructor(props){
    super(props);
    Admob.initialize('Removed for privacy')
    this.state = {};

  }
  onBannerPress() {
    console.log('add button butotn pushed')
    Analytics.logEvent('banner_click')

  }

  render(){
    return(
      <View>
        <TouchableWithoutFeedback
          style={styles.adMobTouch}
          onPress={() => this.onBannerPress()}

        >
          <Banner
            size={"SMART_BANNER"}
            unitId={'Removed for private'}
            request={request.build()}
            onAdLoaded={() => {
              console.log('Advert loaded');
            }}
            onAdFailedToLoad={(result) => {
              console.log('result', result)
              console.log('Ad failed to load', arguments)
            }}
          />
        </TouchableWithoutFeedback>
      </View>
    )
  }
}

【问题讨论】:

  • 同样的哥们...同样的场景

标签: android react-native admob


【解决方案1】:

出于开发目的,unitId 需要是预定义值之一https://developers.google.com/admob/android/test-ads?hl=en-GB

  1. 横幅:
    • ca-app-pub-3940256099942544/6300978111
  2. 插页式:
    • ca-app-pub-3940256099942544/1033173712
  3. 插页式视频:
    • ca-app-pub-3940256099942544/8691691433
  4. 奖励视频:
    • ca-app-pub-3940256099942544/5224354917
  5. 原生高级:
    • ca-app-pub-3940256099942544/2247696110
  6. 原生高级视频:
    • ca-app-pub-3940256099942544/1044960115

【讨论】:

    【解决方案2】:

    我也遇到了同样的错误,其实不是错误,你只需要制作一个正式版的apk,当你的用户对admob的点击量这么多时,admob就会开始展示真实的广告,同时你会在开发模式下仍然会看到此错误,但在您的 apk 的生产模式下可以正常工作,只需制作发布 apk,当您的应用程序对广告的请求过多时,广告将在 24 小时内开始!..

    更多信息 ===> https://github.com/invertase/react-native-firebase/issues/2054

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多