当我尝试导入react-native-google-mobile-ads时,Expo在我的iOS构建中给出了多个错误。
Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGoogleMobileAdsModule' could not be found
Invariant Violation: "main" has not been registered.
我重新配置了我的 ios 版本并尝试更改 ios 文件夹中的一些内容,但我不断收到相同的错误
首先,我从 expo 组件中删除了 app.config.js 文件中的 react-native-google-mobile-ads 组件,并将其更改如下:
'react-native-google-mobile-ads': {
ios_app_id: 'ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxx~yyyyyyyyyyyy',
android_app_id: 'ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxx~yyyyyyyyyyyy',
},
然后我将以下内容添加到ios文件夹中的Info.plist文件中:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxx~yyyyyyyyyyyyyy</string>
然后我将以下内容添加到 AppDelegate.m 文件(也在 ios 文件夹中):
#import <GoogleMobileAds/GoogleMobileAds.h>
最后,我在终端中运行了以下命令:
cd ios
rm -rf Pods
rm -rf Podfile.lock
pod install
cd..
expo run:ios