@dashx/react-native 0.1.13 → 0.1.14

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.
@@ -3,23 +3,28 @@ import Foundation
3
3
  @objc(DashXAppDelegate)
4
4
  class DashXAppDelegate: NSObject {
5
5
  static func swizzleDidReceiveRemoteNotification() {
6
- DispatchQueue.main.async {
7
- let appDelegate = UIApplication.shared.delegate
8
- let appDelegateClass = object_getClass(appDelegate)
6
+ let appDelegate = UIApplication.shared.delegate
7
+ let appDelegateClass = object_getClass(appDelegate)
9
8
 
10
- let originalSelector = #selector(UIApplicationDelegate.application(_:didReceiveRemoteNotification:))
11
- let swizzledSelector = #selector(
12
- DashXAppDelegate.self.handleMessage(_:didReceiveRemoteNotification:)
13
- )
9
+ let originalSelector = #selector(UIApplicationDelegate.application(_:didReceiveRemoteNotification:fetchCompletionHandler:))
10
+ let swizzledSelector = #selector(DashXAppDelegate.self.handleMessage(_:didReceiveRemoteNotification:fetchCompletionHandler:))
14
11
 
15
- try? swizzler(appDelegateClass!, DashXAppDelegate.self, originalSelector, swizzledSelector)
12
+ guard let swizzledMethod = class_getInstanceMethod(DashXAppDelegate.self, swizzledSelector) else {
13
+ return
14
+ }
15
+
16
+ if let originalMethod = class_getInstanceMethod(appDelegateClass, originalSelector) {
17
+ // exchange implementation
18
+ method_exchangeImplementations(originalMethod, swizzledMethod)
19
+ } else {
20
+ // add implementation
21
+ class_addMethod(appDelegateClass, swizzledSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))
16
22
  }
17
23
  }
18
24
 
25
+ // Based on - https://firebase.google.com/docs/cloud-messaging/ios/receive
19
26
  @objc
20
- func handleMessage(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
21
- var properties: [String: [String: Any]] = [ "notification": [:] ]
22
-
27
+ func handleMessage(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
23
28
  DashXLog.d(tag: #function, "Received APN: \(userInfo)")
24
29
 
25
30
  guard let remoteMessage = try? FirebaseRemoteMessage(decoding: userInfo) else {
@@ -27,9 +32,7 @@ class DashXAppDelegate: NSObject {
27
32
  return
28
33
  }
29
34
 
30
- properties["notification"]?["title"] = remoteMessage.aps.alert.title
31
- properties["notification"]?["body"] = remoteMessage.aps.alert.body
32
-
33
- DashXEventEmitter.instance.dispatch(name: "messageReceived", body: properties)
35
+ completionHandler(.newData)
36
+ DashXEventEmitter.instance.dispatch(name: "messageReceived", body: userInfo)
34
37
  }
35
38
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dashx/react-native",
3
3
  "title": "DashX React Native",
4
- "version": "0.1.13",
4
+ "version": "0.1.14",
5
5
  "description": "DashX SDK for React Native",
6
6
  "main": "index.js",
7
7
  "files": [