【问题标题】:How to fix 'Invariant Violation: requireNativeComponent: "RNGADBannerView" was not found in the UIManager'?如何修复“不变违规:requireNativeComponent:在 UIManager 中找不到“RNGADBannerView”?
【发布时间】:2024-04-28 04:25:01
【问题描述】:

最近我尝试将 react-native-admob 添加到我的应用程序中。 我在使用 ios 时遇到错误。 不变违规:requireNativeComponent:在 UIManager 中找不到“RNGADBannerView”。

"react": "16.8.6",
"react-native": "0.60.5",
"react-native-admob": "^2.0.0-beta.5",

我将此添加到 podfile。 pod '谷歌-移动-广告-SDK' 然后,再次安装 pod。 光盘 吊舱安装

我还在 info 中添加了 GADApplicationIdentifier。

import {
    AdMobBanner,
  } from 'react-native-admob'


class BannerAds extends Component {

    render() {
    return (

        <AdMobBanner
            style={styles.bottomBanner}
            adSize="banner"
            adUnitID="my app id"
            onAdFailedToLoad={error => console.error(error)}
        />
        // <View>

        // </View>
        )
    }
}

【问题讨论】:

    标签: ios react-native react-native-android ads


    【解决方案1】:

    我不确定这是否仍然有用,但 我再次安装了库

    1. 如果已链接,请运行此命令取消链接,记住反应本机自动链接工作正常 npx react-native unlink react-native-admob
    2. 从项目中删除库 npm unlink react-native-admob -S
    3. 运行 pod 安装 npx pod-installcd ios &amp;&amp; pod install
    4. 再次安装库 npm i react-native-admob -Syarn react-native-admob
    5. 安装完成后,打开ios/Podfile文件,添加以下内容 pod 'Google-Mobile-Ads-SDK', '7.69.0'
    6. 运行 pod 安装

    应该可以解决的。

    【讨论】:

      【解决方案2】:

      我想推荐其他人使用最新版本的 React、React Native 和 react-native-admob。

      在最近的版本中,所有包都支持自动链接。

      这确实有助于我们轻松使用包。

      【讨论】:

        【解决方案3】:

        看起来react-native-admob 包不支持自动链接(在 React Native 0.60 中引入) - 仍然需要手动链接:

        react-native link react-native-admob
        

        【讨论】: