AppDelegate.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. internal import Expo
  2. import React
  3. import ReactAppDependencyProvider
  4. @main
  5. class AppDelegate: ExpoAppDelegate {
  6. var window: UIWindow?
  7. var reactNativeDelegate: ExpoReactNativeFactoryDelegate?
  8. var reactNativeFactory: RCTReactNativeFactory?
  9. public override func application(
  10. _ application: UIApplication,
  11. didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
  12. ) -> Bool {
  13. let delegate = ReactNativeDelegate()
  14. let factory = ExpoReactNativeFactory(delegate: delegate)
  15. delegate.dependencyProvider = RCTAppDependencyProvider()
  16. reactNativeDelegate = delegate
  17. reactNativeFactory = factory
  18. #if os(iOS) || os(tvOS)
  19. window = UIWindow(frame: UIScreen.main.bounds)
  20. factory.startReactNative(
  21. withModuleName: "main",
  22. in: window,
  23. launchOptions: launchOptions)
  24. #endif
  25. return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  26. }
  27. // Linking API
  28. public override func application(
  29. _ app: UIApplication,
  30. open url: URL,
  31. options: [UIApplication.OpenURLOptionsKey: Any] = [:]
  32. ) -> Bool {
  33. return super.application(app, open: url, options: options) || RCTLinkingManager.application(app, open: url, options: options)
  34. }
  35. // Universal Links
  36. public override func application(
  37. _ application: UIApplication,
  38. continue userActivity: NSUserActivity,
  39. restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
  40. ) -> Bool {
  41. let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
  42. return super.application(application, continue: userActivity, restorationHandler: restorationHandler) || result
  43. }
  44. }
  45. class ReactNativeDelegate: ExpoReactNativeFactoryDelegate {
  46. // Extension point for config-plugins
  47. override func sourceURL(for bridge: RCTBridge) -> URL? {
  48. // needed to return the correct URL for expo-dev-client.
  49. bridge.bundleURL ?? bundleURL()
  50. }
  51. override func bundleURL() -> URL? {
  52. #if DEBUG
  53. return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: ".expo/.virtual-metro-entry")
  54. #else
  55. return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
  56. #endif
  57. }
  58. }