You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo SDK35升级37 XCode12.5下ExpoKit报'moduleRegistry'选择器不存在错误

问题根因

XCode 12.5收紧了Objective-C的方法存在性检查,Expo SDK 37对应的UMModuleRegistryHolderReactModule类未将moduleRegistry方法对外公开,旧版XCode仅触发警告,XCode 12.5直接判定为编译错误。

可行解决方案

方案1:直接修改EXAppState.m代码(临时生效)

将报错的代码段替换为通过valueForKey访问私有属性的实现,绕开方法检查:

- (void)setState:(NSString *)state
{
  if (![state isEqualToString:_lastKnownState]) {
    _lastKnownState = state;
    if (_isObserving) {
      [self sendEventWithName:@"appStateDidChange"
                         body:@{@"app_state": _lastKnownState}];
    }
   
    // change state on universal modules
    // TODO: just make EXAppState a universal module implementing UMAppLifecycleService
    // 替换原有报错行,用valueForKey访问未公开的moduleRegistry属性
    id moduleRegistry = [[self.bridge moduleForClass:[UMModuleRegistryHolderReactModule class]] valueForKey:@"moduleRegistry"];
    id<UMAppLifecycleService> lifeCycleManager = [moduleRegistry getModuleImplementingProtocol:@protocol(UMAppLifecycleService)];
    if ([state isEqualToString:@"background"]) {
      [lifeCycleManager setAppStateToBackground];
    } else if ([state isEqualToString:@"active"]) {
      [lifeCycleManager setAppStateToForeground];
    }
  }
}

方案2:添加CocoaPods Post Install钩子(永久生效)

如果项目用CocoaPods管理依赖,可在Podfile中添加自动修改脚本,避免每次执行pod install后手动修改的内容被覆盖:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    # 匹配EXAppState组件自动修改代码
    if target.name == 'EXAppState'
      file_path = "Pods/EXAppState/EXAppState.m"
      old_code = "id<UMAppLifecycleService> lifeCycleManager = [[[self.bridge moduleForClass:[UMModuleRegistryHolderReactModule class]] moduleRegistry] getModuleImplementingProtocol:@protocol(UMAppLifecycleService)];"
      new_code = <<~'CODE'
      id moduleRegistry = [[self.bridge moduleForClass:[UMModuleRegistryHolderReactModule class]] valueForKey:@"moduleRegistry"];
      id<UMAppLifecycleService> lifeCycleManager = [moduleRegistry getModuleImplementingProtocol:@protocol(UMAppLifecycleService)];
      CODE
      text = File.read(file_path)
      File.open(file_path, 'w') { |file| file.puts text.gsub(old_code, new_code) }
    end
  end
end

兜底方案:降级编译错误为警告

如果还有其他类似的selector不存在报错,可在XCode项目的Build Settings中找到Other Objective-C Flags配置项,添加参数-Wno-unknown-selector,直接关闭该类错误的检查,项目可正常编译运行。

注意事项

以上均为Expokit废弃版本适配高版本XCode的临时补丁,功能层面无副作用,可正常上线使用。后续若允许调整工作流,再按官方指引切换到Bare workflow即可。

内容的提问来源于stack exchange,提问作者dani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 02:45:05