如何在 iPhone 上使用 EAS 版本修复 Google 地图错误?

Posted

技术标签:

【中文标题】如何在 iPhone 上使用 EAS 版本修复 Google 地图错误?【英文标题】:How to fix a Google Maps Error with EAS build on iPhone? 【发布时间】:2022-01-13 17:02:42 【问题描述】:

我将 Expo SDK 43 Managed Workflow 项目迁移到 EAS Build。

我使用 Google 地图作为 androidios 的默认地图选择,但是当我导航到带有地图的屏幕时,我收到此错误:

react-native-maps: AirGoogleMaps dir must be added to your xCode project to support GoogleMaps
 on iOS. at node_modules/react-native-maps/lib/components/decorateMapComponent.js:27:54 in <anonymous>

当我按照错误中列出的路径访问我的 node_modules 文件时,它会将我带到“decorateMapComponent.js”,这是一个包含以下代码的 js 文件。

需要修改哪些内容才能让 iOS 上的 EAS 接受 Google 地图?

下面是代码:

import PropTypes from 'prop-types';
import  requireNativeComponent, NativeModules, Platform  from 'react-native';
import  PROVIDER_DEFAULT, PROVIDER_GOOGLE  from './ProviderConstants';

export const SUPPORTED = 'SUPPORTED';
export const USES_DEFAULT_IMPLEMENTATION = 'USES_DEFAULT_IMPLEMENTATION';
export const NOT_SUPPORTED = 'NOT_SUPPORTED';

export function getAirMapName(provider) 
  if (Platform.OS === 'android') 
    return 'AIRMap';
  
  if (provider === PROVIDER_GOOGLE) 
    return 'AIRGoogleMap';
  
  return 'AIRMap';


function getAirComponentName(provider, component) 
  return `$getAirMapName(provider)$component`;


export const contextTypes = 
  provider: PropTypes.string,
;

export const createNotSupportedComponent = message => () => 
  console.error(message);
  return null;
;

function getViewManagerConfig(viewManagerName) 
  const UIManager = NativeModules.UIManager;
  if (!UIManager.getViewManagerConfig) 
    // RN < 0.58
    return UIManager[viewManagerName];
  
  // RN >= 0.58
  return UIManager.getViewManagerConfig(viewManagerName);


export const googleMapIsInstalled = !!getViewManagerConfig(
  getAirMapName(PROVIDER_GOOGLE)
);

export default function decorateMapComponent(
  Component,
   componentType, providers 
) 
  const components = ;

  const getDefaultComponent = () =>
    requireNativeComponent(getAirComponentName(null, componentType), Component);

  Component.contextTypes = contextTypes;

  Component.prototype.getAirComponent = function getAirComponent() 
    const provider = this.context.provider || PROVIDER_DEFAULT;
    if (components[provider]) 
      return components[provider];
    

    if (provider === PROVIDER_DEFAULT) 
      components[PROVIDER_DEFAULT] = getDefaultComponent();
      return components[PROVIDER_DEFAULT];
    

    const providerInfo = providers[provider];
    const platformSupport = providerInfo[Platform.OS];
    const componentName = getAirComponentName(provider, componentType);
    if (platformSupport === NOT_SUPPORTED) 
      components[provider] = createNotSupportedComponent(
        `react-native-maps: $componentName is not supported on $Platform.OS`
      );
     else if (platformSupport === SUPPORTED) 
      if (
        provider !== PROVIDER_GOOGLE ||
        (Platform.OS === 'ios' && googleMapIsInstalled)
      ) 
        components[provider] = requireNativeComponent(componentName, Component);
      
     else 
      // (platformSupport === USES_DEFAULT_IMPLEMENTATION)
      if (!components[PROVIDER_DEFAULT]) 
        components[PROVIDER_DEFAULT] = getDefaultComponent();
      
      components[provider] = components[PROVIDER_DEFAULT];
    

    return components[provider];
  ;

  Component.prototype.getUIManagerCommand = function getUIManagerCommand(name) 
    const componentName = getAirComponentName(
      this.context.provider,
      componentType
    );
    return getViewManagerConfig(componentName).Commands[name];
  ;

  Component.prototype.getMapManagerCommand = function getMapManagerCommand(
    name
  ) 
    const airComponentName = `$getAirComponentName(
      this.context.provider,
      componentType
    )Manager`;
    return NativeModules[airComponentName][name];
  ;

  return Component;

【问题讨论】:

试试这个github.com/react-native-maps/react-native-maps/issues/… @ErikMazzelli 我没有可以像这样安装的原生可可豆荚;我的项目最初是 Expo Managed Workflow 【参考方案1】:

尝试像这样将“expoCli”:“4.13.0”添加到您的 eas.json:

  "cli": 
    "version": ">= 0.41.0"
  ,
  "build": 
    "base": 
      "expoCli": "4.13.0",
    ,
    "simulator": 
      "extends": "base",
      "android": 
        "buildType": "apk"
      ,
      "ios": 
        "simulator": true
      
    ,
    "development": 
      "extends": "base",
      "developmentClient": true,
      "distribution": "internal"
    ,
    "preview": 
      "extends": "base",
      "distribution": "internal"
    ,
    "production": 
      "extends": "base",
      "releaseChannel": "production"
    
  ,
  "submit": 
  


有同样的问题,对我有用。

【讨论】:

很抱歉我的回复延迟了。事实证明,我必须为 iOS 设备本身添加一个 API 密钥,但我无法在 Android 上加载地图。对这个问题有什么想法吗?

以上是关于如何在 iPhone 上使用 EAS 版本修复 Google 地图错误?的主要内容,如果未能解决你的问题,请参考以下文章

金蝶eas如何关闭自动更新

新赛季多线程技术开放机型,优化团战帧率!26个BUG修复

如何在同一部 iPhone 中获取两个不同版本的可执行文件?使用 Xcode

如何使用 G++ 和 CPLEX 修复此“未定义引用”错误?

如何修复 g++ 内存范围重叠?

如何修复我的 [UIScreen 主屏幕] 将 iPhone 5 识别为 iPhone 4