如何修复 'Invariant Violation: requireNativeComponent: "RNGADBannerView" was not found in the UIManager'?

How to fix 'Invariant Violation: requireNativeComponent: "RNGADBannerView" was not found in the UIManager'?

最近我尝试将 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。 吊舱 'Google-Mobile-Ads-SDK' 然后,再次安装 pod。 CD ios pod 安装

我还在信息中添加了 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>
        )
    }
}

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

react-native link react-native-admob

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

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

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

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

  1. 运行 如果已链接,此命令将取消链接,请记住 React Native 自动链接工作正常 npx react-native unlink react-native-admob
  2. 从项目中删除库 npm unlink react-native-admob -S
  3. 运行 pod 安装 npx pod-installcd ios && 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 安装

应该可以解决。