@react-native-firebase/messaging 23.7.0 → 23.8.0

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.
Files changed (109) hide show
  1. package/dist/commonjs/index.js +61 -0
  2. package/dist/commonjs/index.js.map +1 -0
  3. package/dist/commonjs/modular.js +439 -0
  4. package/dist/commonjs/modular.js.map +1 -0
  5. package/dist/commonjs/namespaced.js +407 -0
  6. package/dist/commonjs/namespaced.js.map +1 -0
  7. package/dist/commonjs/package.json +1 -0
  8. package/dist/commonjs/remoteMessageOptions.js +87 -0
  9. package/dist/commonjs/remoteMessageOptions.js.map +1 -0
  10. package/dist/commonjs/statics.js +29 -0
  11. package/dist/commonjs/statics.js.map +1 -0
  12. package/dist/commonjs/types/messaging.js +105 -0
  13. package/dist/commonjs/types/messaging.js.map +1 -0
  14. package/dist/commonjs/version.js +9 -0
  15. package/dist/commonjs/version.js.map +1 -0
  16. package/{ios/RNFBMessaging/RNFBMessaging+FIRMessagingDelegate.h → dist/module/index.js} +11 -12
  17. package/dist/module/index.js.map +1 -0
  18. package/{lib/modular/index.js → dist/module/modular.js} +135 -119
  19. package/dist/module/modular.js.map +1 -0
  20. package/{lib/index.js → dist/module/namespaced.js} +70 -193
  21. package/dist/module/namespaced.js.map +1 -0
  22. package/dist/module/package.json +1 -0
  23. package/{lib → dist/module}/remoteMessageOptions.js +10 -27
  24. package/dist/module/remoteMessageOptions.js.map +1 -0
  25. package/dist/module/statics.js +25 -0
  26. package/dist/module/statics.js.map +1 -0
  27. package/dist/module/types/messaging.js +124 -0
  28. package/dist/module/types/messaging.js.map +1 -0
  29. package/dist/module/version.js +5 -0
  30. package/dist/module/version.js.map +1 -0
  31. package/dist/typescript/commonjs/lib/index.d.ts +6 -0
  32. package/dist/typescript/commonjs/lib/index.d.ts.map +1 -0
  33. package/{lib/modular/index.d.ts → dist/typescript/commonjs/lib/modular.d.ts} +86 -164
  34. package/dist/typescript/commonjs/lib/modular.d.ts.map +1 -0
  35. package/dist/typescript/commonjs/lib/namespaced.d.ts +12 -0
  36. package/dist/typescript/commonjs/lib/namespaced.d.ts.map +1 -0
  37. package/dist/typescript/commonjs/lib/remoteMessageOptions.d.ts +14 -0
  38. package/dist/typescript/commonjs/lib/remoteMessageOptions.d.ts.map +1 -0
  39. package/dist/typescript/commonjs/lib/statics.d.ts +20 -0
  40. package/dist/typescript/commonjs/lib/statics.d.ts.map +1 -0
  41. package/dist/typescript/commonjs/lib/types/messaging.d.ts +673 -0
  42. package/dist/typescript/commonjs/lib/types/messaging.d.ts.map +1 -0
  43. package/dist/typescript/commonjs/lib/version.d.ts +2 -0
  44. package/dist/typescript/commonjs/lib/version.d.ts.map +1 -0
  45. package/dist/typescript/commonjs/package.json +1 -0
  46. package/dist/typescript/module/lib/index.d.ts +6 -0
  47. package/dist/typescript/module/lib/index.d.ts.map +1 -0
  48. package/dist/typescript/module/lib/modular.d.ts +247 -0
  49. package/dist/typescript/module/lib/modular.d.ts.map +1 -0
  50. package/dist/typescript/module/lib/namespaced.d.ts +12 -0
  51. package/dist/typescript/module/lib/namespaced.d.ts.map +1 -0
  52. package/dist/typescript/module/lib/remoteMessageOptions.d.ts +14 -0
  53. package/dist/typescript/module/lib/remoteMessageOptions.d.ts.map +1 -0
  54. package/dist/typescript/module/lib/statics.d.ts +20 -0
  55. package/dist/typescript/module/lib/statics.d.ts.map +1 -0
  56. package/dist/typescript/module/lib/types/messaging.d.ts +673 -0
  57. package/dist/typescript/module/lib/types/messaging.d.ts.map +1 -0
  58. package/dist/typescript/module/lib/version.d.ts +2 -0
  59. package/dist/typescript/module/lib/version.d.ts.map +1 -0
  60. package/dist/typescript/module/package.json +1 -0
  61. package/{ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.h → lib/index.ts} +28 -21
  62. package/lib/modular.ts +447 -0
  63. package/lib/namespaced.ts +583 -0
  64. package/lib/remoteMessageOptions.ts +110 -0
  65. package/lib/{statics.js → statics.ts} +6 -3
  66. package/lib/types/messaging.ts +815 -0
  67. package/lib/version.ts +2 -0
  68. package/package.json +64 -8
  69. package/tsconfig.json +21 -0
  70. package/CHANGELOG.md +0 -1181
  71. package/RNFBMessaging.podspec +0 -50
  72. package/android/.editorconfig +0 -10
  73. package/android/build.gradle +0 -149
  74. package/android/lint.xml +0 -5
  75. package/android/settings.gradle +0 -1
  76. package/android/src/main/AndroidManifest.xml +0 -43
  77. package/android/src/main/java/io/invertase/firebase/messaging/JsonConvert.java +0 -127
  78. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingHeadlessService.java +0 -30
  79. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingModule.java +0 -332
  80. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingPackage.java +0 -41
  81. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingReceiver.java +0 -66
  82. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingSerializer.java +0 -225
  83. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingService.java +0 -37
  84. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingStore.java +0 -15
  85. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingStoreHelper.java +0 -23
  86. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingStoreImpl.java +0 -97
  87. package/android/src/main/res/values/colors.xml +0 -143
  88. package/app.plugin.js +0 -1
  89. package/ios/RNFBMessaging/RNFBMessaging+AppDelegate.h +0 -54
  90. package/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m +0 -251
  91. package/ios/RNFBMessaging/RNFBMessaging+FIRMessagingDelegate.m +0 -70
  92. package/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.h +0 -29
  93. package/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m +0 -173
  94. package/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m +0 -185
  95. package/ios/RNFBMessaging/RNFBMessagingModule.h +0 -26
  96. package/ios/RNFBMessaging/RNFBMessagingModule.m +0 -431
  97. package/ios/RNFBMessaging/RNFBMessagingSerializer.h +0 -32
  98. package/ios/RNFBMessaging/RNFBMessagingSerializer.m +0 -235
  99. package/ios/RNFBMessaging.xcodeproj/project.pbxproj +0 -384
  100. package/ios/RNFBMessaging.xcodeproj/xcshareddata/IDETemplateMacros.plist +0 -24
  101. package/lib/index.d.ts +0 -1233
  102. package/lib/version.js +0 -2
  103. package/plugin/build/android/index.d.ts +0 -2
  104. package/plugin/build/android/index.js +0 -5
  105. package/plugin/build/android/setupFirebaseNotifationIcon.d.ts +0 -8
  106. package/plugin/build/android/setupFirebaseNotifationIcon.js +0 -62
  107. package/plugin/build/index.d.ts +0 -3
  108. package/plugin/build/index.js +0 -16
  109. package/plugin/tsconfig.tsbuildinfo +0 -1
@@ -1,37 +0,0 @@
1
- package io.invertase.firebase.messaging;
2
-
3
- import com.google.firebase.messaging.FirebaseMessagingService;
4
- import com.google.firebase.messaging.RemoteMessage;
5
- import io.invertase.firebase.common.ReactNativeFirebaseEventEmitter;
6
-
7
- public class ReactNativeFirebaseMessagingService extends FirebaseMessagingService {
8
- @Override
9
- public void onSendError(String messageId, Exception sendError) {
10
- ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
11
- emitter.sendEvent(
12
- ReactNativeFirebaseMessagingSerializer.messageSendErrorToEvent(messageId, sendError));
13
- }
14
-
15
- @Override
16
- public void onDeletedMessages() {
17
- ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
18
- emitter.sendEvent(ReactNativeFirebaseMessagingSerializer.messagesDeletedToEvent());
19
- }
20
-
21
- @Override
22
- public void onMessageSent(String messageId) {
23
- ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
24
- emitter.sendEvent(ReactNativeFirebaseMessagingSerializer.messageSentToEvent(messageId));
25
- }
26
-
27
- @Override
28
- public void onNewToken(String token) {
29
- ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
30
- emitter.sendEvent(ReactNativeFirebaseMessagingSerializer.newTokenToTokenEvent(token));
31
- }
32
-
33
- @Override
34
- public void onMessageReceived(RemoteMessage remoteMessage) {
35
- // noop - handled in receiver
36
- }
37
- }
@@ -1,15 +0,0 @@
1
- package io.invertase.firebase.messaging;
2
-
3
- import com.facebook.react.bridge.WritableMap;
4
- import com.google.firebase.messaging.RemoteMessage;
5
-
6
- public interface ReactNativeFirebaseMessagingStore {
7
- void storeFirebaseMessage(RemoteMessage remoteMessage);
8
-
9
- @Deprecated
10
- RemoteMessage getFirebaseMessage(String remoteMessageId);
11
-
12
- WritableMap getFirebaseMessageMap(String remoteMessageId);
13
-
14
- void clearFirebaseMessage(String remoteMessageId);
15
- }
@@ -1,23 +0,0 @@
1
- package io.invertase.firebase.messaging;
2
-
3
- public class ReactNativeFirebaseMessagingStoreHelper {
4
-
5
- private ReactNativeFirebaseMessagingStore messagingStore;
6
-
7
- private ReactNativeFirebaseMessagingStoreHelper() {
8
- messagingStore = new ReactNativeFirebaseMessagingStoreImpl();
9
- }
10
-
11
- private static ReactNativeFirebaseMessagingStoreHelper _instance;
12
-
13
- public static ReactNativeFirebaseMessagingStoreHelper getInstance() {
14
- if (_instance == null) {
15
- _instance = new ReactNativeFirebaseMessagingStoreHelper();
16
- }
17
- return _instance;
18
- }
19
-
20
- public ReactNativeFirebaseMessagingStore getMessagingStore() {
21
- return messagingStore;
22
- }
23
- }
@@ -1,97 +0,0 @@
1
- package io.invertase.firebase.messaging;
2
-
3
- import static io.invertase.firebase.messaging.JsonConvert.jsonToReact;
4
- import static io.invertase.firebase.messaging.JsonConvert.reactToJSON;
5
- import static io.invertase.firebase.messaging.ReactNativeFirebaseMessagingSerializer.remoteMessageFromReadableMap;
6
- import static io.invertase.firebase.messaging.ReactNativeFirebaseMessagingSerializer.remoteMessageToWritableMap;
7
-
8
- import com.facebook.react.bridge.ReadableMap;
9
- import com.facebook.react.bridge.WritableMap;
10
- import com.google.firebase.messaging.RemoteMessage;
11
- import io.invertase.firebase.common.UniversalFirebasePreferences;
12
- import java.util.ArrayList;
13
- import java.util.Arrays;
14
- import java.util.List;
15
- import org.json.JSONException;
16
- import org.json.JSONObject;
17
-
18
- public class ReactNativeFirebaseMessagingStoreImpl implements ReactNativeFirebaseMessagingStore {
19
-
20
- private static final String S_KEY_ALL_NOTIFICATION_IDS = "all_notification_ids";
21
- private static final int MAX_SIZE_NOTIFICATIONS = 100;
22
- private final String DELIMITER = ",";
23
-
24
- @Override
25
- public void storeFirebaseMessage(RemoteMessage remoteMessage) {
26
- try {
27
- String remoteMessageString =
28
- reactToJSON(remoteMessageToWritableMap(remoteMessage)).toString();
29
- // Log.d("storeFirebaseMessage", remoteMessageString);
30
- UniversalFirebasePreferences preferences = UniversalFirebasePreferences.getSharedInstance();
31
-
32
- // remove old notifications message before store to free space as needed
33
- String notificationIds = preferences.getStringValue(S_KEY_ALL_NOTIFICATION_IDS, "");
34
- List<String> allNotificationList = convertToArray(notificationIds);
35
- while (allNotificationList.size() > MAX_SIZE_NOTIFICATIONS - 1) {
36
- clearFirebaseMessage(allNotificationList.get(0));
37
- allNotificationList.remove(0);
38
- }
39
-
40
- // now refetch the ids after possible removals, and store the new message
41
- notificationIds = preferences.getStringValue(S_KEY_ALL_NOTIFICATION_IDS, "");
42
- preferences.setStringValue(remoteMessage.getMessageId(), remoteMessageString);
43
- // save new notification id
44
- notificationIds += remoteMessage.getMessageId() + DELIMITER; // append to last
45
- preferences.setStringValue(S_KEY_ALL_NOTIFICATION_IDS, notificationIds);
46
- } catch (JSONException e) {
47
- e.printStackTrace();
48
- }
49
- }
50
-
51
- @Deprecated
52
- @Override
53
- public RemoteMessage getFirebaseMessage(String remoteMessageId) {
54
- ReadableMap messageMap = getFirebaseMessageMap(remoteMessageId);
55
- if (messageMap != null) {
56
- return remoteMessageFromReadableMap(messageMap);
57
- }
58
- return null;
59
- }
60
-
61
- @Override
62
- public WritableMap getFirebaseMessageMap(String remoteMessageId) {
63
- String remoteMessageString =
64
- UniversalFirebasePreferences.getSharedInstance().getStringValue(remoteMessageId, null);
65
- if (remoteMessageString != null) {
66
- // Log.d("getFirebaseMessage", remoteMessageString);
67
- try {
68
- WritableMap remoteMessageMap = jsonToReact(new JSONObject(remoteMessageString));
69
- remoteMessageMap.putString("to", remoteMessageId); // fake to
70
- return remoteMessageMap;
71
- } catch (JSONException e) {
72
- e.printStackTrace();
73
- }
74
- }
75
- return null;
76
- }
77
-
78
- @Override
79
- public void clearFirebaseMessage(String remoteMessageId) {
80
- UniversalFirebasePreferences preferences = UniversalFirebasePreferences.getSharedInstance();
81
- preferences.remove(remoteMessageId).apply();
82
- // check and remove old notifications message
83
- String notificationIds = preferences.getStringValue(S_KEY_ALL_NOTIFICATION_IDS, "");
84
- if (!notificationIds.isEmpty()) {
85
- notificationIds = removeRemoteMessageId(remoteMessageId, notificationIds); // remove from list
86
- preferences.setStringValue(S_KEY_ALL_NOTIFICATION_IDS, notificationIds);
87
- }
88
- }
89
-
90
- private String removeRemoteMessageId(String remoteMessageId, String notificationIds) {
91
- return notificationIds.replace(remoteMessageId + DELIMITER, "");
92
- }
93
-
94
- private List<String> convertToArray(String string) {
95
- return new ArrayList<>(Arrays.asList(string.split(DELIMITER)));
96
- }
97
- }
@@ -1,143 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <resources>
3
- <color name="white">#FFFFFF</color>
4
- <color name="ivory">#FFFFF0</color>
5
- <color name="lightyellow">#FFFFE0</color>
6
- <color name="yellow">#FFFF00</color>
7
- <color name="snow">#FFFAFA</color>
8
- <color name="floralwhite">#FFFAF0</color>
9
- <color name="lemonchiffon">#FFFACD</color>
10
- <color name="cornsilk">#FFF8DC</color>
11
- <color name="seashell">#FFF5EE</color>
12
- <color name="lavenderblush">#FFF0F5</color>
13
- <color name="papayawhip">#FFEFD5</color>
14
- <color name="blanchedalmond">#FFEBCD</color>
15
- <color name="mistyrose">#FFE4E1</color>
16
- <color name="bisque">#FFE4C4</color>
17
- <color name="moccasin">#FFE4B5</color>
18
- <color name="navajowhite">#FFDEAD</color>
19
- <color name="peachpuff">#FFDAB9</color>
20
- <color name="gold">#FFD700</color>
21
- <color name="pink">#FFC0CB</color>
22
- <color name="lightpink">#FFB6C1</color>
23
- <color name="orange">#FFA500</color>
24
- <color name="lightsalmon">#FFA07A</color>
25
- <color name="darkorange">#FF8C00</color>
26
- <color name="coral">#FF7F50</color>
27
- <color name="hotpink">#FF69B4</color>
28
- <color name="tomato">#FF6347</color>
29
- <color name="orangered">#FF4500</color>
30
- <color name="deeppink">#FF1493</color>
31
- <color name="fuchsia">#FF00FF</color>
32
- <color name="magenta">#FF00FF</color>
33
- <color name="red">#FF0000</color>
34
- <color name="oldlace">#FDF5E6</color>
35
- <color name="lightgoldenrodyellow">#FAFAD2</color>
36
- <color name="linen">#FAF0E6</color>
37
- <color name="antiquewhite">#FAEBD7</color>
38
- <color name="salmon">#FA8072</color>
39
- <color name="ghostwhite">#F8F8FF</color>
40
- <color name="mintcream">#F5FFFA</color>
41
- <color name="whitesmoke">#F5F5F5</color>
42
- <color name="beige">#F5F5DC</color>
43
- <color name="wheat">#F5DEB3</color>
44
- <color name="sandybrown">#F4A460</color>
45
- <color name="azure">#F0FFFF</color>
46
- <color name="honeydew">#F0FFF0</color>
47
- <color name="aliceblue">#F0F8FF</color>
48
- <color name="khaki">#F0E68C</color>
49
- <color name="lightcoral">#F08080</color>
50
- <color name="palegoldenrod">#EEE8AA</color>
51
- <color name="violet">#EE82EE</color>
52
- <color name="darksalmon">#E9967A</color>
53
- <color name="lavender">#E6E6FA</color>
54
- <color name="lightcyan">#E0FFFF</color>
55
- <color name="burlywood">#DEB887</color>
56
- <color name="plum">#DDA0DD</color>
57
- <color name="gainsboro">#DCDCDC</color>
58
- <color name="crimson">#DC143C</color>
59
- <color name="palevioletred">#DB7093</color>
60
- <color name="goldenrod">#DAA520</color>
61
- <color name="orchid">#DA70D6</color>
62
- <color name="thistle">#D8BFD8</color>
63
- <color name="lightgrey">#D3D3D3</color>
64
- <color name="tan">#D2B48C</color>
65
- <color name="chocolate">#D2691E</color>
66
- <color name="peru">#CD853F</color>
67
- <color name="indianred">#CD5C5C</color>
68
- <color name="mediumvioletred">#C71585</color>
69
- <color name="silver">#C0C0C0</color>
70
- <color name="darkkhaki">#BDB76B</color>
71
- <color name="rosybrown">#BC8F8F</color>
72
- <color name="mediumorchid">#BA55D3</color>
73
- <color name="darkgoldenrod">#B8860B</color>
74
- <color name="firebrick">#B22222</color>
75
- <color name="powderblue">#B0E0E6</color>
76
- <color name="lightsteelblue">#B0C4DE</color>
77
- <color name="paleturquoise">#AFEEEE</color>
78
- <color name="greenyellow">#ADFF2F</color>
79
- <color name="lightblue">#ADD8E6</color>
80
- <color name="darkgray">#A9A9A9</color>
81
- <color name="brown">#A52A2A</color>
82
- <color name="sienna">#A0522D</color>
83
- <color name="yellowgreen">#9ACD32</color>
84
- <color name="darkorchid">#9932CC</color>
85
- <color name="palegreen">#98FB98</color>
86
- <color name="darkviolet">#9400D3</color>
87
- <color name="mediumpurple">#9370DB</color>
88
- <color name="lightgreen">#90EE90</color>
89
- <color name="darkseagreen">#8FBC8F</color>
90
- <color name="saddlebrown">#8B4513</color>
91
- <color name="darkmagenta">#8B008B</color>
92
- <color name="darkred">#8B0000</color>
93
- <color name="blueviolet">#8A2BE2</color>
94
- <color name="lightskyblue">#87CEFA</color>
95
- <color name="skyblue">#87CEEB</color>
96
- <color name="gray">#808080</color>
97
- <color name="olive">#808000</color>
98
- <color name="purple">#800080</color>
99
- <color name="maroon">#800000</color>
100
- <color name="aquamarine">#7FFFD4</color>
101
- <color name="chartreuse">#7FFF00</color>
102
- <color name="lawngreen">#7CFC00</color>
103
- <color name="mediumslateblue">#7B68EE</color>
104
- <color name="lightslategray">#778899</color>
105
- <color name="slategray">#708090</color>
106
- <color name="olivedrab">#6B8E23</color>
107
- <color name="slateblue">#6A5ACD</color>
108
- <color name="dimgray">#696969</color>
109
- <color name="mediumaquamarine">#66CDAA</color>
110
- <color name="cornflowerblue">#6495ED</color>
111
- <color name="cadetblue">#5F9EA0</color>
112
- <color name="darkolivegreen">#556B2F</color>
113
- <color name="indigo">#4B0082</color>
114
- <color name="mediumturquoise">#48D1CC</color>
115
- <color name="darkslateblue">#483D8B</color>
116
- <color name="steelblue">#4682B4</color>
117
- <color name="royalblue">#4169E1</color>
118
- <color name="turquoise">#40E0D0</color>
119
- <color name="mediumseagreen">#3CB371</color>
120
- <color name="limegreen">#32CD32</color>
121
- <color name="darkslategray">#2F4F4F</color>
122
- <color name="seagreen">#2E8B57</color>
123
- <color name="forestgreen">#228B22</color>
124
- <color name="lightseagreen">#20B2AA</color>
125
- <color name="dodgerblue">#1E90FF</color>
126
- <color name="midnightblue">#191970</color>
127
- <color name="aqua">#00FFFF</color>
128
- <color name="cyan">#00FFFF</color>
129
- <color name="springgreen">#00FF7F</color>
130
- <color name="lime">#00FF00</color>
131
- <color name="mediumspringgreen">#00FA9A</color>
132
- <color name="darkturquoise">#00CED1</color>
133
- <color name="deepskyblue">#00BFFF</color>
134
- <color name="darkcyan">#008B8B</color>
135
- <color name="teal">#008080</color>
136
- <color name="green">#008000</color>
137
- <color name="darkgreen">#006400</color>
138
- <color name="blue">#0000FF</color>
139
- <color name="mediumblue">#0000CD</color>
140
- <color name="darkblue">#00008B</color>
141
- <color name="navy">#000080</color>
142
- <color name="black">#000000</color>
143
- </resources>
package/app.plugin.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./plugin/build');
@@ -1,54 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- #import <Foundation/Foundation.h>
19
- #import <React/RCTBridgeModule.h>
20
- #import <UIKit/UIKit.h>
21
-
22
- NS_ASSUME_NONNULL_BEGIN
23
-
24
- @interface RNFBMessagingAppDelegate : NSObject <UIApplicationDelegate>
25
-
26
- @property _Nullable RCTPromiseRejectBlock registerPromiseRejecter;
27
- @property _Nullable RCTPromiseResolveBlock registerPromiseResolver;
28
- @property(nonatomic, strong) NSCondition *conditionBackgroundMessageHandlerSet;
29
- @property(nonatomic) BOOL backgroundMessageHandlerSet;
30
- @property(nonatomic, copy) void (^completionHandler)(UIBackgroundFetchResult);
31
- @property(nonatomic, assign) UIBackgroundTaskIdentifier backgroundTaskId;
32
-
33
- + (_Nonnull instancetype)sharedInstance;
34
-
35
- - (void)observe;
36
-
37
- - (void)signalBackgroundMessageHandlerSet;
38
-
39
- - (void)setPromiseResolve:(RCTPromiseResolveBlock)resolve
40
- andPromiseReject:(RCTPromiseRejectBlock)reject;
41
-
42
- - (void)application:(UIApplication *)application
43
- didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
44
-
45
- - (void)application:(UIApplication *)application
46
- didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
47
-
48
- - (void)application:(UIApplication *)application
49
- didReceiveRemoteNotification:(NSDictionary *)userInfo
50
- fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;
51
-
52
- @end
53
-
54
- NS_ASSUME_NONNULL_END
@@ -1,251 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- #import <Firebase/Firebase.h>
19
- #import <GoogleUtilities/GULAppDelegateSwizzler.h>
20
- #import <objc/runtime.h>
21
-
22
- #import <RNFBApp/RNFBRCTEventEmitter.h>
23
- #import <RNFBApp/RNFBSharedUtils.h>
24
- #import <React/RCTConvert.h>
25
-
26
- #import "RNFBMessaging+AppDelegate.h"
27
- #import "RNFBMessagingSerializer.h"
28
-
29
- @implementation RNFBMessagingAppDelegate
30
-
31
- + (instancetype)sharedInstance {
32
- static dispatch_once_t once;
33
- __strong static RNFBMessagingAppDelegate *sharedInstance;
34
- dispatch_once(&once, ^{
35
- sharedInstance = [[RNFBMessagingAppDelegate alloc] init];
36
- sharedInstance.conditionBackgroundMessageHandlerSet = [[NSCondition alloc] init];
37
- sharedInstance.backgroundMessageHandlerSet = NO;
38
- });
39
- return sharedInstance;
40
- }
41
-
42
- - (void)observe {
43
- static dispatch_once_t once;
44
- __weak RNFBMessagingAppDelegate *weakSelf = self;
45
- dispatch_once(&once, ^{
46
- RNFBMessagingAppDelegate *strongSelf = weakSelf;
47
-
48
- [GULAppDelegateSwizzler registerAppDelegateInterceptor:strongSelf];
49
- [GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods];
50
-
51
- SEL didReceiveRemoteNotificationWithCompletionSEL =
52
- NSSelectorFromString(@"application:didReceiveRemoteNotification:fetchCompletionHandler:");
53
- if ([[GULAppDelegateSwizzler sharedApplication].delegate
54
- respondsToSelector:didReceiveRemoteNotificationWithCompletionSEL]) {
55
- // noop - user has own implementation of this method in their AppDelegate, this
56
- // means GULAppDelegateSwizzler will have already replaced it with a donor method
57
- } else {
58
- // add our own donor implementation of
59
- // application:didReceiveRemoteNotification:fetchCompletionHandler:
60
- Method donorMethod = class_getInstanceMethod(object_getClass(strongSelf),
61
- didReceiveRemoteNotificationWithCompletionSEL);
62
- class_addMethod(object_getClass([GULAppDelegateSwizzler sharedApplication].delegate),
63
- didReceiveRemoteNotificationWithCompletionSEL,
64
- method_getImplementation(donorMethod), method_getTypeEncoding(donorMethod));
65
- }
66
- });
67
- }
68
-
69
- // used to signal that a javascript handler for background messages is set
70
- - (void)signalBackgroundMessageHandlerSet {
71
- RNFBMessagingAppDelegate *sharedInstance = [RNFBMessagingAppDelegate sharedInstance];
72
- [sharedInstance.conditionBackgroundMessageHandlerSet lock];
73
- DLog(@"signalBackgroundMessageHandlerSet sharedInstance.backgroundMessageHandlerSet was %@",
74
- sharedInstance.backgroundMessageHandlerSet ? @"YES" : @"NO");
75
- sharedInstance.backgroundMessageHandlerSet = YES;
76
- [sharedInstance.conditionBackgroundMessageHandlerSet broadcast];
77
- [sharedInstance.conditionBackgroundMessageHandlerSet unlock];
78
- }
79
-
80
- // used to temporarily store a promise instance to resolve calls to `registerForRemoteNotifications`
81
- - (void)setPromiseResolve:(RCTPromiseResolveBlock)resolve
82
- andPromiseReject:(RCTPromiseRejectBlock)reject {
83
- _registerPromiseResolver = resolve;
84
- _registerPromiseRejecter = reject;
85
- }
86
-
87
- #pragma mark -
88
- #pragma mark AppDelegate Methods
89
-
90
- // called when `registerForRemoteNotifications` completes successfully
91
- - (void)application:(UIApplication *)application
92
- didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
93
- #ifdef DEBUG
94
- [[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRMessagingAPNSTokenTypeSandbox];
95
- #else
96
- [[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRMessagingAPNSTokenTypeProd];
97
- #endif
98
-
99
- if (_registerPromiseResolver != nil) {
100
- _registerPromiseResolver(@(
101
- [RCTConvert BOOL:@([UIApplication sharedApplication].isRegisteredForRemoteNotifications)]));
102
- _registerPromiseResolver = nil;
103
- _registerPromiseRejecter = nil;
104
- }
105
- }
106
-
107
- // called when `registerForRemoteNotifications` fails to complete
108
- - (void)application:(UIApplication *)application
109
- didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
110
- if (_registerPromiseRejecter != nil) {
111
- [RNFBSharedUtils rejectPromiseWithNSError:_registerPromiseRejecter error:error];
112
- _registerPromiseResolver = nil;
113
- _registerPromiseRejecter = nil;
114
- }
115
- }
116
-
117
- - (void)application:(UIApplication *)application
118
- didReceiveRemoteNotification:(NSDictionary *)userInfo
119
- fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
120
- #if __has_include(<FirebaseAuth/FirebaseAuth.h>)
121
-
122
- for (id appId in [FIRApp allApps]) {
123
- FIRApp *app = [[FIRApp allApps] objectForKey:appId];
124
- if ([[FIRAuth authWithApp:app] canHandleNotification:userInfo]) {
125
- DLog(@"didReceiveRemoteNotification Firebase Auth handled the notification with instance: %@",
126
- app.name);
127
- completionHandler(UIBackgroundFetchResultNoData);
128
- return;
129
- }
130
- }
131
-
132
- // If the notification is a probe notification, always call the completion
133
- // handler with UIBackgroundFetchResultNoData.
134
- //
135
- // This fixes a race condition between `FIRAuth/didReceiveRemoteNotification` and this
136
- // module causing detox to hang when `FIRAuth/didReceiveRemoteNotification` is called first.
137
- // see
138
- // https://stackoverflow.com/questions/72044950/detox-tests-hang-with-pending-items-on-dispatch-queue/72989494
139
- NSDictionary *data = userInfo[@"com.google.firebase.auth"];
140
- if ([data isKindOfClass:[NSString class]]) {
141
- // Deserialize in case the data is a JSON string.
142
- NSData *JSONData = [((NSString *)data) dataUsingEncoding:NSUTF8StringEncoding];
143
- data = [NSJSONSerialization JSONObjectWithData:JSONData options:0 error:NULL];
144
- }
145
- if ([data isKindOfClass:[NSDictionary class]] && data[@"warning"]) {
146
- completionHandler(UIBackgroundFetchResultNoData);
147
- return;
148
- }
149
- #endif
150
-
151
- [[NSNotificationCenter defaultCenter]
152
- postNotificationName:@"RNFBMessagingDidReceiveRemoteNotification"
153
- object:userInfo];
154
-
155
- if (userInfo[@"gcm.message_id"]) {
156
- DLog(@"didReceiveRemoteNotification gcm.message_id was present %@", userInfo);
157
-
158
- if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
159
- // Store the completion handler to call later when the JS code finishes
160
- RNFBMessagingAppDelegate *sharedInstance = [RNFBMessagingAppDelegate sharedInstance];
161
- sharedInstance.completionHandler = completionHandler;
162
-
163
- // If app is in background state, register background task to guarantee async queues aren't
164
- // frozen.
165
- sharedInstance.backgroundTaskId = [application beginBackgroundTaskWithExpirationHandler:^{
166
- dispatch_get_main_queue(), ^{
167
- if (sharedInstance.backgroundTaskId != UIBackgroundTaskInvalid) {
168
- [application endBackgroundTask:sharedInstance.backgroundTaskId];
169
- sharedInstance.backgroundTaskId = UIBackgroundTaskInvalid;
170
- }
171
- };
172
- }];
173
-
174
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(25 * NSEC_PER_SEC)),
175
- dispatch_get_main_queue(), ^{
176
- if (sharedInstance.completionHandler) {
177
- sharedInstance.completionHandler(UIBackgroundFetchResultNewData);
178
- sharedInstance.completionHandler = nil;
179
- }
180
-
181
- // Stop background task after the longest timeout, async queue is okay to
182
- // freeze again after handling period
183
- if (sharedInstance.backgroundTaskId != UIBackgroundTaskInvalid) {
184
- [application endBackgroundTask:sharedInstance.backgroundTaskId];
185
- sharedInstance.backgroundTaskId = UIBackgroundTaskInvalid;
186
- }
187
- });
188
-
189
- [sharedInstance.conditionBackgroundMessageHandlerSet lock];
190
- @try {
191
- DLog(@"didReceiveRemoteNotification sharedInstance.backgroundMessageHandlerSet = %@",
192
- sharedInstance.backgroundMessageHandlerSet ? @"YES" : @"NO");
193
- if (sharedInstance.backgroundMessageHandlerSet) {
194
- // Normal path, backgroundMessageHandlerSet has already been set, queue the notification
195
- // for immediate delivery
196
- dispatch_async(dispatch_get_main_queue(), ^{
197
- [[RNFBRCTEventEmitter shared]
198
- sendEventWithName:@"messaging_message_received_background"
199
- body:[RNFBMessagingSerializer remoteMessageUserInfoToDict:userInfo]];
200
- });
201
- DLog(@"didReceiveRemoteNotification without waiting for backgroundMessageHandlerSet to "
202
- @"be set");
203
- } else {
204
- // This spin needs to be on a background/concurrent queue to await the setup of
205
- // backgroundMessageHandlerSet and not block the main thread
206
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
207
- // Reaquire the lock in this new closure
208
- [sharedInstance.conditionBackgroundMessageHandlerSet lock];
209
- @try {
210
- // Spin/wait until backgroundMessageHandlerSet
211
- // NB it is possible while this closure was being scheduled that
212
- // backgroundMessageHandlerSet is already set and this loop is skipped
213
- while (!sharedInstance.backgroundMessageHandlerSet) {
214
- DLog(@"didReceiveRemoteNotification waiting for "
215
- @"sharedInstance.backgroundMessageHandlerSet %@",
216
- sharedInstance.backgroundMessageHandlerSet ? @"YES" : @"NO");
217
- if (![sharedInstance.conditionBackgroundMessageHandlerSet
218
- waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:25]]) {
219
- // If after 25 seconds the client hasn't called backgroundMessageHandlerSet, give
220
- // up on this notification
221
- ELog(@"didReceiveRemoteNotification timed out waiting for "
222
- @"sharedInstance.backgroundMessageHandlerSet");
223
- return;
224
- }
225
- }
226
- dispatch_async(dispatch_get_main_queue(), ^{
227
- [[RNFBRCTEventEmitter shared]
228
- sendEventWithName:@"messaging_message_received_background"
229
- body:[RNFBMessagingSerializer
230
- remoteMessageUserInfoToDict:userInfo]];
231
- });
232
- DLog(@"didReceiveRemoteNotification after waiting for backgroundMessageHandlerSet");
233
- } @finally {
234
- [sharedInstance.conditionBackgroundMessageHandlerSet unlock];
235
- }
236
- });
237
- }
238
- } @finally {
239
- [sharedInstance.conditionBackgroundMessageHandlerSet unlock];
240
- }
241
- } else {
242
- DLog(@"didReceiveRemoteNotification while app was in foreground");
243
- [[RNFBRCTEventEmitter shared]
244
- sendEventWithName:@"messaging_message_received"
245
- body:[RNFBMessagingSerializer remoteMessageUserInfoToDict:userInfo]];
246
- completionHandler(UIBackgroundFetchResultNoData);
247
- }
248
- }
249
- }
250
-
251
- @end