Keine Beschreibung

AppDelegate.swift 2.2KB

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