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

RN 0.74.2集成Expo SDK 51后iOS启动崩溃:bundleURL未实现

解决裸React Native 0.74.2 + Expo SDK 51 iOS启动崩溃(RCTAppDelegate::bundleURL not implemented)

问题原因

错误提示Subclasses must implement a valid getBundleURL method说明你的iOS AppDelegate未正确实现bundleURL方法,在RN 0.74+与Expo SDK 51的集成场景下,需要确保AppDelegate继承Expo代理类并提供JS bundle的加载路径。

解决方案

1. 更新iOS AppDelegate文件

根据你使用的语言(Objective-C/Swift)修改对应的文件:

Objective-C(AppDelegate.mm)

替换原有内容为:

#import "AppDelegate.h"
#import <Expo/Expo.h>

@interface AppDelegate () <EXAppDelegateDelegate>
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [EXAppDelegateWrapper sharedInstance].delegate = self;
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)bundleURL
{
#ifdef DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

Swift(AppDelegate.swift)

替换原有内容为:

import UIKit
import ExpoModulesCore

class AppDelegate: EXAppDelegateWrapper {
  override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    delegate = self
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

  override var bundleURL: URL {
    #if DEBUG
      return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
    #else
      return Bundle.main.url(forResource: "main", withExtension: "jsbundle")!
    #endif
  }
}

extension AppDelegate: EXAppDelegateDelegate {}

2. 验证配置一致性

  • 确认app.json/app.config.js中ios.bundleIdentifier与Xcode项目的Bundle ID完全一致(当前为org.reactjs.native.example.OnSight)
  • 执行npx expo install同步所有Expo依赖版本

3. 重新构建项目

# 清理Xcode构建缓存
xcodebuild clean

# 重新安装iOS Pods
cd ios && pod install && cd ..

# 重新运行项目
npx expo run:ios

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 23:33:20