@dashx/react-native 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DashX.podspec +1 -4
- package/README.md +12 -3
- package/ios/DashX.swift +7 -7
- package/ios/DashXAppDelegate.swift +17 -13
- package/package.json +1 -1
package/DashX.podspec
CHANGED
package/README.md
CHANGED
|
@@ -49,15 +49,19 @@ apply plugin: 'com.google.gms.google-services'
|
|
|
49
49
|
|
|
50
50
|
### Setup for iOS
|
|
51
51
|
|
|
52
|
-
- At the top of the file `/ios/{projectName}/AppDelegate.m` import Firebase:
|
|
52
|
+
- At the top of the file `/ios/{projectName}/AppDelegate.m` before [#if defined(FB_SONARKIT_ENABLED)](https://github.com/react-native-camera/react-native-camera/issues/3008#issuecomment-726432198), import Firebase:
|
|
53
53
|
|
|
54
54
|
```objective-c
|
|
55
|
-
#import <
|
|
55
|
+
#import <FirebaseCore/FirebaseCore.h>
|
|
56
|
+
#import <FirebaseMessaging/FirebaseMessaging.h>
|
|
56
57
|
```
|
|
57
58
|
|
|
58
59
|
- In the same file, inside your `didFinishLaunchingWithOptions` add this:
|
|
59
60
|
|
|
60
61
|
```objective-c
|
|
62
|
+
// Register for remote notifications. This shows a permission dialog on first run, to
|
|
63
|
+
// show the dialog at a more appropriate time move this registration accordingly.
|
|
64
|
+
// [START register_for_notifications]
|
|
61
65
|
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
|
|
62
66
|
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
|
|
63
67
|
UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
|
|
@@ -67,18 +71,23 @@ UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
|
|
|
67
71
|
}];
|
|
68
72
|
|
|
69
73
|
[application registerForRemoteNotifications];
|
|
74
|
+
// [END register_for_notifications]
|
|
70
75
|
|
|
76
|
+
// [START configure_firebase]
|
|
71
77
|
if ([FIRApp defaultApp] == nil) {
|
|
72
78
|
[FIRApp configure];
|
|
73
79
|
}
|
|
80
|
+
// [END configure_firebase]
|
|
74
81
|
|
|
82
|
+
// [START set_messaging_delegate]
|
|
75
83
|
[FIRMessaging messaging].delegate = self;
|
|
84
|
+
// [END set_messaging_delegate]
|
|
76
85
|
```
|
|
77
86
|
|
|
78
87
|
- In your `Podfile` add this:
|
|
79
88
|
|
|
80
89
|
```ruby
|
|
81
|
-
pod '
|
|
90
|
+
pod 'FirebaseMessaging', :modular_headers => true
|
|
82
91
|
```
|
|
83
92
|
|
|
84
93
|
- Add your iOS app on Firebase Console: `Project Overview > Add App > iOS`
|
package/ios/DashX.swift
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
-
import
|
|
2
|
+
import FirebaseMessaging
|
|
3
3
|
|
|
4
4
|
@objc(DashX)
|
|
5
5
|
class DashX: RCTEventEmitter {
|
|
@@ -45,12 +45,13 @@ class DashX: RCTEventEmitter {
|
|
|
45
45
|
UIViewController.swizzle()
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
// Based on https://firebase.google.com/docs/cloud-messaging/ios/client#access_the_registration_token
|
|
49
|
+
Messaging.messaging().token { token, error in
|
|
49
50
|
if let error = error {
|
|
50
|
-
DashXLog.d(tag: #function, "Error fetching
|
|
51
|
-
} else if let
|
|
52
|
-
DashXLog.d(tag: #function, "Firebase initialised with: \(
|
|
53
|
-
self.dashXClient.setDeviceToken(to:
|
|
51
|
+
DashXLog.d(tag: #function, "Error fetching FCM registration token: \(error)")
|
|
52
|
+
} else if let token = token {
|
|
53
|
+
DashXLog.d(tag: #function, "Firebase initialised with: \(token)")
|
|
54
|
+
self.dashXClient.setDeviceToken(to: token)
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -145,5 +146,4 @@ class DashX: RCTEventEmitter {
|
|
|
145
146
|
func subscribe() {
|
|
146
147
|
dashXClient.subscribe()
|
|
147
148
|
}
|
|
148
|
-
|
|
149
149
|
}
|
|
@@ -3,22 +3,26 @@ import Foundation
|
|
|
3
3
|
@objc(DashXAppDelegate)
|
|
4
4
|
class DashXAppDelegate: NSObject {
|
|
5
5
|
static func swizzleDidReceiveRemoteNotificationFetchCompletionHandler() {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// To remove the warning -[UIApplication delegate] must be called from main thread only
|
|
7
|
+
// and to call the UI controlling method from the main thread, use `DispatchQueue.main.async`
|
|
8
|
+
DispatchQueue.main.async {
|
|
9
|
+
let appDelegate = UIApplication.shared.delegate
|
|
10
|
+
let appDelegateClass: AnyClass? = object_getClass(appDelegate)
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
let originalSelector = #selector(UIApplicationDelegate.application(_:didReceiveRemoteNotification:fetchCompletionHandler:))
|
|
13
|
+
let swizzledSelector = #selector(DashXAppDelegate.self.handleMessage(_:didReceiveRemoteNotification:fetchCompletionHandler:))
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
guard let swizzledMethod = class_getInstanceMethod(DashXAppDelegate.self, swizzledSelector) else {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
if let originalMethod = class_getInstanceMethod(appDelegateClass, originalSelector) {
|
|
20
|
+
// exchange implementation
|
|
21
|
+
method_exchangeImplementations(originalMethod, swizzledMethod)
|
|
22
|
+
} else {
|
|
23
|
+
// add implementation
|
|
24
|
+
class_addMethod(appDelegateClass, swizzledSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
|