如何解决React Native的UIManager错误中找不到“ AIRMap”?

时间:2018-07-13 05:14:46

标签: ios react-native react-native-maps

未处理的JS异常:始终违规:requireNativeComponent:在UIManager中找不到“ AIRMap”。

  

此错误位于:       在AIRMap中(位于MapView.js:760)       在MapView中(位于App.js:25)       在RCTView中(在View.js:43)       在App中(在renderApplication.js:32)       在RCTView中(在View.js:43)       在RCTView中(在View.js:43)       在AppContainer中(在renderApplication.js:31)

如何在响应本机ios中解决此错误?

4 个答案:

答案 0 :(得分:1)

添加到ios/YOUR_PROJECT_NAME/AppDelegate.m

@import GoogleMaps; //add this line if you want to use Google Maps

[GMSServices provideAPIKey:@"_YOUR_API_KEY_"]; // add this line using the api key obtained from Google Console

答案 1 :(得分:1)

我也有这个错误,我以这种方式解决了:

  1. 在您的项目中,转到package.json
  2. 在依赖关系下,本机映射应如下所示:“ react-native-maps”:“ https://github.com/react-community/react-native-maps.git
  3. 转到终端/ cmd并运行npm-install
  4. 不要忘记链接:“ react-native链接react-native-maps”

  5. 然后:react-native run-ios / android

由于只允许一个人在npm发布,我们应该使用Git进行最新更新,等等。

答案 2 :(得分:0)

我在package.json中添加了以下脚本。它对我有用。

{
  "name": "your-app",
  "scripts": {
    "postinstall": "./node_modules/react-native-maps/enable-google-maps REPLACE_ME_RELATIVE_PATH_TO_GOOGLE_MAPS_INSTALL"
  }
}

答案 3 :(得分:-3)

/*----------------Install----------------*/

npm install react-native-maps --save

/*----------------Get a Google Maps API key----------------*/

/*----------------Write this in Pod file----------------*/

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target '_YOUR_PROJECT_TARGET_' do
    rn_path = '../node_modules/react-native'
    rn_maps_path = '../node_modules/react-native-maps'

# See http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies
    pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
pod 'React', path: rn_path, subspecs: [
    'Core',
    'CxxBridge',
    'DevSupport',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
]

# React Native third party dependencies podspecs
pod 'DoubleConversion', :podspec => "#{rn_path}/third-party-podspecs/DoubleConversion.podspec"
pod 'glog', :podspec => "#{rn_path}/third-party-podspecs/glog.podspec"
# If you are using React Native <0.54, you will get the following error:
    # "The name of the given podspec `GLog` doesn't match the expected one `glog`"
# Use the following line instead:
    #pod 'GLog', :podspec => "#{rn_path}/third-party-podspecs/GLog.podspec"
pod 'Folly', :podspec => "#{rn_path}/third-party-podspecs/Folly.podspec"

# react-native-maps dependencies
pod 'react-native-maps', path: rn_maps_path
pod 'react-native-google-maps', path: rn_maps_path  # Remove this line if you don't want to support GoogleMaps on iOS
pod 'GoogleMaps'  # Remove this line if you don't want to support GoogleMaps on iOS
pod 'Google-Maps-iOS-Utils' # Remove this line if you don't want to support GoogleMaps on iOS
end

post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'react-native-google-maps'
    target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_MODULES'] = 'No'
end
end
if target.name == "React"
    target.remove_from_project
end
end
end



/*----------------Write this in AppDelegate .m----------------*/

@import GoogleMaps

In didFinishLaunchingWithOptions method
    [GMSServices provideAPIKey:@"_YOUR_API_KEY_"];

/*----------------Now rut it with simulator or iOS device----------------*/

/*----------------

for more you can take reference of this :
https://github.com/react-community/react-native-maps

----------------*/