-
Notifications
You must be signed in to change notification settings - Fork 375
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
54 lines (46 loc) · 1.75 KB
/
Copy pathAppDelegate.swift
File metadata and controls
54 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import UIKit
import React
import React_RCTAppDelegate
import ReactAppDependencyProvider
import FirebaseCore
import FirebaseMessaging
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// Unused with the scene lifecycle (SceneDelegate owns the window), but Firebase's
// app delegate proxy (GULAppDelegateSwizzler) exposes the optional `window` selector,
// so UIKit calls it and crashes if the property is missing.
var window: UIWindow?
var reactNativeDelegate: ReactNativeDelegate?
var reactNativeFactory: RCTReactNativeFactory?
// Kept for SceneDelegate, which starts React Native once the scene connects
var launchOptions: [UIApplication.LaunchOptionsKey: Any]?
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
let delegate = ReactNativeDelegate()
let factory = RCTReactNativeFactory(delegate: delegate)
delegate.dependencyProvider = RCTAppDependencyProvider()
FirebaseApp.configure()
reactNativeDelegate = delegate
reactNativeFactory = factory
self.launchOptions = launchOptions
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Pass the device token to FCM
Messaging.messaging().apnsToken = deviceToken
}
}
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
override func sourceURL(for bridge: RCTBridge) -> URL? {
self.bundleURL()
}
override func bundleURL() -> URL? {
#if DEBUG
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
#else
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
}
}