react-native-push-signal 0.1.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.
- package/LICENSE +20 -0
- package/PushSignal.podspec +31 -0
- package/README.md +125 -0
- package/README.ru.md +125 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +115 -0
- package/android/src/main/AndroidManifest.xml +18 -0
- package/android/src/main/cpp/cpp-adapter.cpp +11 -0
- package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignal.kt +44 -0
- package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignalCenter.kt +353 -0
- package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignalInitProvider.kt +34 -0
- package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignalMessagingService.kt +15 -0
- package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignalPackage.kt +22 -0
- package/ios/PushSignal.swift +38 -0
- package/ios/PushSignalCenter.swift +430 -0
- package/ios/PushSignalLaunchStore.h +21 -0
- package/ios/PushSignalLaunchStore.m +26 -0
- package/lib/module/PushSignal.nitro.js +4 -0
- package/lib/module/PushSignal.nitro.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/pushSignal.js +19 -0
- package/lib/module/pushSignal.js.map +1 -0
- package/lib/module/pushSignal.native.js +46 -0
- package/lib/module/pushSignal.native.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/PushSignal.nitro.d.ts +33 -0
- package/lib/typescript/src/PushSignal.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/pushSignal.d.ts +8 -0
- package/lib/typescript/src/pushSignal.d.ts.map +1 -0
- package/lib/typescript/src/pushSignal.native.d.ts +8 -0
- package/lib/typescript/src/pushSignal.native.d.ts.map +1 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/android/c++/JAndroidFirebaseConfig.hpp +70 -0
- package/nitrogen/generated/android/c++/JFunc_void_PushMessage.hpp +80 -0
- package/nitrogen/generated/android/c++/JHybridPushSignalSpec.cpp +138 -0
- package/nitrogen/generated/android/c++/JHybridPushSignalSpec.hpp +68 -0
- package/nitrogen/generated/android/c++/JPermissionStatus.hpp +61 -0
- package/nitrogen/generated/android/c++/JPushCredentials.hpp +70 -0
- package/nitrogen/generated/android/c++/JPushEnvironment.hpp +58 -0
- package/nitrogen/generated/android/c++/JPushMessage.hpp +84 -0
- package/nitrogen/generated/android/c++/JPushPlatform.hpp +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/AndroidFirebaseConfig.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/Func_void_PushMessage.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/HybridPushSignalSpec.kt +87 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/PermissionStatus.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/PushCredentials.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/PushEnvironment.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/PushMessage.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/PushPlatform.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/pushsignalOnLoad.kt +35 -0
- package/nitrogen/generated/android/pushsignal+autolinking.cmake +81 -0
- package/nitrogen/generated/android/pushsignal+autolinking.gradle +27 -0
- package/nitrogen/generated/android/pushsignalOnLoad.cpp +56 -0
- package/nitrogen/generated/android/pushsignalOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/PushSignal+autolinking.rb +62 -0
- package/nitrogen/generated/ios/PushSignal-Swift-Cxx-Bridge.cpp +65 -0
- package/nitrogen/generated/ios/PushSignal-Swift-Cxx-Bridge.hpp +257 -0
- package/nitrogen/generated/ios/PushSignal-Swift-Cxx-Umbrella.hpp +66 -0
- package/nitrogen/generated/ios/PushSignalAutolinking.mm +33 -0
- package/nitrogen/generated/ios/PushSignalAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridPushSignalSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridPushSignalSpecSwift.hpp +137 -0
- package/nitrogen/generated/ios/swift/AndroidFirebaseConfig.swift +96 -0
- package/nitrogen/generated/ios/swift/Func_void_PermissionStatus.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_PushCredentials.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_PushMessage.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridPushSignalSpec.swift +60 -0
- package/nitrogen/generated/ios/swift/HybridPushSignalSpec_cxx.swift +226 -0
- package/nitrogen/generated/ios/swift/PermissionStatus.swift +44 -0
- package/nitrogen/generated/ios/swift/PushCredentials.swift +45 -0
- package/nitrogen/generated/ios/swift/PushEnvironment.swift +40 -0
- package/nitrogen/generated/ios/swift/PushMessage.swift +97 -0
- package/nitrogen/generated/ios/swift/PushPlatform.swift +40 -0
- package/nitrogen/generated/shared/c++/AndroidFirebaseConfig.hpp +96 -0
- package/nitrogen/generated/shared/c++/HybridPushSignalSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridPushSignalSpec.hpp +79 -0
- package/nitrogen/generated/shared/c++/PermissionStatus.hpp +80 -0
- package/nitrogen/generated/shared/c++/PushCredentials.hpp +97 -0
- package/nitrogen/generated/shared/c++/PushEnvironment.hpp +76 -0
- package/nitrogen/generated/shared/c++/PushMessage.hpp +97 -0
- package/nitrogen/generated/shared/c++/PushPlatform.hpp +76 -0
- package/package.json +187 -0
- package/src/PushSignal.nitro.ts +37 -0
- package/src/index.tsx +16 -0
- package/src/pushSignal.native.tsx +67 -0
- package/src/pushSignal.tsx +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anton Seagull
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "PushSignal"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://antonseagull.com.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = [
|
|
17
|
+
"ios/**/*.{swift}",
|
|
18
|
+
"ios/**/*.{h,m,mm}",
|
|
19
|
+
"cpp/**/*.{hpp,cpp}",
|
|
20
|
+
]
|
|
21
|
+
s.public_header_files = "ios/**/*.h"
|
|
22
|
+
s.frameworks = "UIKit", "UserNotifications"
|
|
23
|
+
|
|
24
|
+
s.dependency 'React-jsi'
|
|
25
|
+
s.dependency 'React-callinvoker'
|
|
26
|
+
|
|
27
|
+
load 'nitrogen/generated/ios/PushSignal+autolinking.rb'
|
|
28
|
+
add_nitrogen_files(s)
|
|
29
|
+
|
|
30
|
+
install_modules_dependencies(s)
|
|
31
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# react-native-push-signal
|
|
2
|
+
|
|
3
|
+
English | [Русский](README.ru.md)
|
|
4
|
+
|
|
5
|
+
Get push permission, device credentials for your server, and listen for incoming notifications or taps. The library does not send pushes — your backend talks to APNs and FCM.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install react-native-push-signal react-native-nitro-modules
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react-native-nitro-modules` is required because this library uses [Nitro Modules](https://nitro.margelo.com/).
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {
|
|
19
|
+
getCredentials,
|
|
20
|
+
getPermissionStatus,
|
|
21
|
+
initialize,
|
|
22
|
+
onMessage,
|
|
23
|
+
onNotificationPress,
|
|
24
|
+
requestPermission,
|
|
25
|
+
} from 'react-native-push-signal';
|
|
26
|
+
|
|
27
|
+
initialize({
|
|
28
|
+
projectId: 'my-project',
|
|
29
|
+
applicationId: '1:123456789:android:abcd',
|
|
30
|
+
apiKey: 'AIza...',
|
|
31
|
+
gcmSenderId: '123456789',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const status = await getPermissionStatus();
|
|
35
|
+
const afterRequest = await requestPermission();
|
|
36
|
+
const credentials = await getCredentials();
|
|
37
|
+
// POST credentials to your server: { platform, token, environment? }
|
|
38
|
+
|
|
39
|
+
const stopMessages = onMessage((message) => {
|
|
40
|
+
console.log('incoming', message);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const stopPress = onNotificationPress((message) => {
|
|
44
|
+
console.log('opened from notification', message);
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`onNotificationPress` also delivers the tap that launched the app if you subscribe after startup.
|
|
49
|
+
|
|
50
|
+
### What to send to your server
|
|
51
|
+
|
|
52
|
+
| Platform | `credentials.token` | Server sends through |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| iOS | APNs device token (hex) | Apple APNs HTTP/2 |
|
|
55
|
+
| Android | FCM registration token | Firebase Cloud Messaging HTTP v1 |
|
|
56
|
+
|
|
57
|
+
Keep Apple `.p8` keys and the Firebase service account on the server. The app never sees them.
|
|
58
|
+
|
|
59
|
+
`environment` is iOS-only: `sandbox` for development builds, `production` for TestFlight / App Store.
|
|
60
|
+
|
|
61
|
+
## iOS setup
|
|
62
|
+
|
|
63
|
+
1. Enable **Push Notifications** on the app target.
|
|
64
|
+
2. Enable **Background Modes → Remote notifications**.
|
|
65
|
+
3. Use a physical device. The simulator cannot register with APNs.
|
|
66
|
+
|
|
67
|
+
The library hooks `UNUserNotificationCenter` and APNs token callbacks, so the host `AppDelegate` does not need extra code.
|
|
68
|
+
|
|
69
|
+
## Android setup
|
|
70
|
+
|
|
71
|
+
Remote Android pushes go through FCM. You can either pass the client Firebase fields at runtime or use `google-services.json`.
|
|
72
|
+
|
|
73
|
+
### Runtime config (no file in the APK)
|
|
74
|
+
|
|
75
|
+
Call `initialize` with values from `google-services.json` (not a service account):
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
initialize({
|
|
79
|
+
projectId: '...', // project_id
|
|
80
|
+
applicationId: '...', // mobilesdk_app_id
|
|
81
|
+
apiKey: '...', // current_key
|
|
82
|
+
gcmSenderId: '...', // project_number
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
All four fields are required for Firebase to start. If any is missing, `initialize` does nothing and does not throw. iOS ignores this call.
|
|
87
|
+
|
|
88
|
+
Keep the Firebase service account on your server. Do not put it in the app.
|
|
89
|
+
|
|
90
|
+
### google-services.json
|
|
91
|
+
|
|
92
|
+
Alternatively, add Firebase to the host app:
|
|
93
|
+
|
|
94
|
+
1. Place `google-services.json` in `android/app`.
|
|
95
|
+
2. Apply the Google Services plugin in `android/app/build.gradle`:
|
|
96
|
+
|
|
97
|
+
```gradle
|
|
98
|
+
apply plugin: "com.google.gms.google-services"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
3. Add the plugin classpath in `android/build.gradle` / `settings.gradle` as in the [Firebase Android setup](https://firebase.google.com/docs/android/setup).
|
|
102
|
+
|
|
103
|
+
Without `initialize(...)` or that file, `getCredentials()` throws. Notification permission (`POST_NOTIFICATIONS`) is requested on API 33+.
|
|
104
|
+
|
|
105
|
+
If the host app already declares its own `FirebaseMessagingService`, only one service can handle `com.google.firebase.MESSAGING_EVENT`. Prefer this library’s service or forward events into it.
|
|
106
|
+
|
|
107
|
+
## Incoming messages vs taps
|
|
108
|
+
|
|
109
|
+
- `onMessage` — the push arrived while the app is in the foreground (and Android data messages while the process is alive). The library does not draw a banner.
|
|
110
|
+
- `onNotificationPress` — the user opened the notification, including a cold start.
|
|
111
|
+
- On iOS, a visible push received in the background or when the app is killed is delivered on tap, not through `onMessage`. That is an OS limit.
|
|
112
|
+
|
|
113
|
+
## Web
|
|
114
|
+
|
|
115
|
+
Permission helpers resolve to `denied`. `getCredentials()` throws. Listeners are no-ops.
|
|
116
|
+
|
|
117
|
+
## Contributing
|
|
118
|
+
|
|
119
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
120
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
121
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|
package/README.ru.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# react-native-push-signal
|
|
2
|
+
|
|
3
|
+
[English](README.md) | Русский
|
|
4
|
+
|
|
5
|
+
Библиотека запрашивает разрешение на пуши, отдаёт токен устройства для вашего сервера и сообщает о входящем уведомлении или нажатии на него. Сами пуши она не отправляет — в APNs и FCM ходит бэкенд.
|
|
6
|
+
|
|
7
|
+
## Установка
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install react-native-push-signal react-native-nitro-modules
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react-native-nitro-modules` обязателен: библиотека собрана на [Nitro Modules](https://nitro.margelo.com/).
|
|
14
|
+
|
|
15
|
+
## Использование
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {
|
|
19
|
+
getCredentials,
|
|
20
|
+
getPermissionStatus,
|
|
21
|
+
initialize,
|
|
22
|
+
onMessage,
|
|
23
|
+
onNotificationPress,
|
|
24
|
+
requestPermission,
|
|
25
|
+
} from 'react-native-push-signal';
|
|
26
|
+
|
|
27
|
+
initialize({
|
|
28
|
+
projectId: 'my-project',
|
|
29
|
+
applicationId: '1:123456789:android:abcd',
|
|
30
|
+
apiKey: 'AIza...',
|
|
31
|
+
gcmSenderId: '123456789',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const status = await getPermissionStatus();
|
|
35
|
+
const afterRequest = await requestPermission();
|
|
36
|
+
const credentials = await getCredentials();
|
|
37
|
+
// POST credentials на сервер: { platform, token, environment? }
|
|
38
|
+
|
|
39
|
+
const stopMessages = onMessage((message) => {
|
|
40
|
+
console.log('incoming', message);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const stopPress = onNotificationPress((message) => {
|
|
44
|
+
console.log('opened from notification', message);
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Если приложение открыли из уведомления до подписки, `onNotificationPress` всё равно отдаст этот тап сразу после `onNotificationPress(...)`.
|
|
49
|
+
|
|
50
|
+
### Что отправлять на сервер
|
|
51
|
+
|
|
52
|
+
| Платформа | `credentials.token` | Куда сервер шлёт пуш |
|
|
53
|
+
| --------- | ----------------------- | -------------------------------- |
|
|
54
|
+
| iOS | APNs device token (hex) | Apple APNs HTTP/2 |
|
|
55
|
+
| Android | FCM registration token | Firebase Cloud Messaging HTTP v1 |
|
|
56
|
+
|
|
57
|
+
Ключи Apple `.p8` и service account Firebase остаются на сервере. Приложение их не видит.
|
|
58
|
+
|
|
59
|
+
`environment` есть только на iOS: `sandbox` для dev-сборок, `production` для TestFlight и App Store.
|
|
60
|
+
|
|
61
|
+
## Настройка iOS
|
|
62
|
+
|
|
63
|
+
1. Включите **Push Notifications** у app target.
|
|
64
|
+
2. Включите **Background Modes → Remote notifications**.
|
|
65
|
+
3. Проверяйте на физическом устройстве. Симулятор не умеет регистрироваться в APNs.
|
|
66
|
+
|
|
67
|
+
Библиотека сама подписывается на `UNUserNotificationCenter` и колбеки APNs-токена. В `AppDelegate` хоста ничего дописывать не нужно.
|
|
68
|
+
|
|
69
|
+
## Настройка Android
|
|
70
|
+
|
|
71
|
+
Удалённые пуши на Android идут через FCM. Можно передать клиентские поля Firebase в рантайме или положить `google-services.json`.
|
|
72
|
+
|
|
73
|
+
### Конфиг в рантайме (без файла в APK)
|
|
74
|
+
|
|
75
|
+
Вызовите `initialize` со значениями из `google-services.json` (не из service account):
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
initialize({
|
|
79
|
+
projectId: '...', // project_id
|
|
80
|
+
applicationId: '...', // mobilesdk_app_id
|
|
81
|
+
apiKey: '...', // current_key
|
|
82
|
+
gcmSenderId: '...', // project_number
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Нужны все четыре поля. Если чего-то нет, `initialize` тихо ничего не делает и не бросает ошибку. На iOS вызов игнорируется.
|
|
87
|
+
|
|
88
|
+
Service account Firebase оставляйте на сервере. В приложение его класть нельзя.
|
|
89
|
+
|
|
90
|
+
### google-services.json
|
|
91
|
+
|
|
92
|
+
Либо подключите Firebase в хост-приложение:
|
|
93
|
+
|
|
94
|
+
1. Положите `google-services.json` в `android/app`.
|
|
95
|
+
2. Подключите плагин Google Services в `android/app/build.gradle`:
|
|
96
|
+
|
|
97
|
+
```gradle
|
|
98
|
+
apply plugin: "com.google.gms.google-services"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
3. Добавьте classpath плагина в `android/build.gradle` / `settings.gradle` по [инструкции Firebase для Android](https://firebase.google.com/docs/android/setup).
|
|
102
|
+
|
|
103
|
+
Без `initialize(...)` или этого файла `getCredentials()` бросит ошибку. Разрешение на уведомления (`POST_NOTIFICATIONS`) запрашивается на API 33+.
|
|
104
|
+
|
|
105
|
+
Если в хост-приложении уже есть свой `FirebaseMessagingService`, обработать `com.google.firebase.MESSAGING_EVENT` может только один сервис. Оставьте сервис этой библиотеки или пробрасывайте события в него.
|
|
106
|
+
|
|
107
|
+
## Входящее сообщение и тап
|
|
108
|
+
|
|
109
|
+
- `onMessage` — пуш пришёл, пока приложение на переднем плане (и Android data-message, пока процесс жив). Баннер библиотека не рисует.
|
|
110
|
+
- `onNotificationPress` — пользователь открыл уведомление, в том числе при холодном старте.
|
|
111
|
+
- На iOS видимый пуш в фоне или при убитом приложении приходит только в тап, не в `onMessage`. Это ограничение ОС.
|
|
112
|
+
|
|
113
|
+
## Web
|
|
114
|
+
|
|
115
|
+
Методы разрешения возвращают `denied`. `getCredentials()` бросает ошибку. Слушатели ничего не делают.
|
|
116
|
+
|
|
117
|
+
## Contributing
|
|
118
|
+
|
|
119
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
120
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
121
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
project(pushsignal)
|
|
2
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
3
|
+
|
|
4
|
+
set(PACKAGE_NAME pushsignal)
|
|
5
|
+
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
7
|
+
|
|
8
|
+
# Define C++ library and add all sources
|
|
9
|
+
add_library(${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp)
|
|
10
|
+
|
|
11
|
+
# Add Nitrogen specs :)
|
|
12
|
+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/pushsignal+autolinking.cmake)
|
|
13
|
+
|
|
14
|
+
# Set up local includes
|
|
15
|
+
include_directories("src/main/cpp" "../cpp")
|
|
16
|
+
|
|
17
|
+
find_library(LOG_LIB log)
|
|
18
|
+
|
|
19
|
+
# Link all libraries together
|
|
20
|
+
target_link_libraries(
|
|
21
|
+
${PACKAGE_NAME}
|
|
22
|
+
${LOG_LIB}
|
|
23
|
+
android # <-- Android core
|
|
24
|
+
)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.PushSignal = [
|
|
3
|
+
kotlinVersion: "2.0.21",
|
|
4
|
+
minSdkVersion: 24,
|
|
5
|
+
compileSdkVersion: 36
|
|
6
|
+
]
|
|
7
|
+
|
|
8
|
+
ext.getExtOrDefault = { prop ->
|
|
9
|
+
if (rootProject.ext.has(prop)) {
|
|
10
|
+
return rootProject.ext.get(prop)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return PushSignal[prop]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
repositories {
|
|
17
|
+
google()
|
|
18
|
+
mavenCentral()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
dependencies {
|
|
22
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
23
|
+
// noinspection DifferentKotlinGradleVersion
|
|
24
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
def reactNativeArchitectures() {
|
|
29
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
30
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
apply plugin: "com.android.library"
|
|
34
|
+
apply plugin: "kotlin-android"
|
|
35
|
+
apply from: '../nitrogen/generated/android/pushsignal+autolinking.gradle'
|
|
36
|
+
|
|
37
|
+
apply plugin: "com.facebook.react"
|
|
38
|
+
|
|
39
|
+
android {
|
|
40
|
+
namespace "com.margelo.nitro.pushsignal"
|
|
41
|
+
|
|
42
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
43
|
+
|
|
44
|
+
defaultConfig {
|
|
45
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
46
|
+
|
|
47
|
+
externalNativeBuild {
|
|
48
|
+
cmake {
|
|
49
|
+
cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
|
|
50
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
51
|
+
abiFilters (*reactNativeArchitectures())
|
|
52
|
+
|
|
53
|
+
buildTypes {
|
|
54
|
+
debug {
|
|
55
|
+
cppFlags "-O1 -g"
|
|
56
|
+
}
|
|
57
|
+
release {
|
|
58
|
+
cppFlags "-O2"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
externalNativeBuild {
|
|
66
|
+
cmake {
|
|
67
|
+
path "CMakeLists.txt"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
packaging {
|
|
72
|
+
resources {
|
|
73
|
+
excludes += [
|
|
74
|
+
"META-INF",
|
|
75
|
+
"META-INF/**"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
jniLibs {
|
|
80
|
+
excludes += [
|
|
81
|
+
"**/libc++_shared.so",
|
|
82
|
+
"**/libfbjni.so",
|
|
83
|
+
"**/libjsi.so",
|
|
84
|
+
"**/libfolly_json.so",
|
|
85
|
+
"**/libfolly_runtime.so",
|
|
86
|
+
"**/libglog.so",
|
|
87
|
+
"**/libhermes.so",
|
|
88
|
+
"**/libhermes-executor-debug.so",
|
|
89
|
+
"**/libhermes_executor.so",
|
|
90
|
+
"**/libreactnative.so",
|
|
91
|
+
"**/libreactnativejni.so",
|
|
92
|
+
"**/libturbomodulejsijni.so",
|
|
93
|
+
"**/libreact_nativemodule_core.so",
|
|
94
|
+
"**/libjscexecutor.so"
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
buildFeatures {
|
|
100
|
+
prefab true
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
compileOptions {
|
|
104
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
105
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
dependencies {
|
|
110
|
+
implementation "com.facebook.react:react-android"
|
|
111
|
+
implementation project(":react-native-nitro-modules")
|
|
112
|
+
implementation "androidx.activity:activity-ktx:1.10.1"
|
|
113
|
+
implementation "androidx.core:core-ktx:1.16.0"
|
|
114
|
+
implementation "com.google.firebase:firebase-messaging:24.1.2"
|
|
115
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
3
|
+
|
|
4
|
+
<application>
|
|
5
|
+
<provider
|
|
6
|
+
android:name="com.margelo.nitro.pushsignal.PushSignalInitProvider"
|
|
7
|
+
android:authorities="${applicationId}.pushsignal.init"
|
|
8
|
+
android:exported="false" />
|
|
9
|
+
|
|
10
|
+
<service
|
|
11
|
+
android:name="com.margelo.nitro.pushsignal.PushSignalMessagingService"
|
|
12
|
+
android:exported="false">
|
|
13
|
+
<intent-filter>
|
|
14
|
+
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
|
15
|
+
</intent-filter>
|
|
16
|
+
</service>
|
|
17
|
+
</application>
|
|
18
|
+
</manifest>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package com.margelo.nitro.pushsignal
|
|
2
|
+
|
|
3
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
4
|
+
import com.margelo.nitro.core.Promise
|
|
5
|
+
|
|
6
|
+
@DoNotStrip
|
|
7
|
+
class PushSignal : HybridPushSignalSpec() {
|
|
8
|
+
override fun initialize(config: AndroidFirebaseConfig) {
|
|
9
|
+
PushSignalCenter.initialize(config)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
override fun getPermissionStatus(): Promise<PermissionStatus> {
|
|
13
|
+
return Promise.async {
|
|
14
|
+
PushSignalCenter.getPermissionStatus()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override fun requestPermission(): Promise<PermissionStatus> {
|
|
19
|
+
val promise = Promise<PermissionStatus>()
|
|
20
|
+
PushSignalCenter.requestPermission { status ->
|
|
21
|
+
promise.resolve(status)
|
|
22
|
+
}
|
|
23
|
+
return promise
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
override fun getCredentials(): Promise<PushCredentials> {
|
|
27
|
+
return Promise.async {
|
|
28
|
+
val token = PushSignalCenter.fetchToken()
|
|
29
|
+
PushCredentials(
|
|
30
|
+
PushPlatform.ANDROID,
|
|
31
|
+
token,
|
|
32
|
+
null
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override fun setOnMessage(callback: (message: PushMessage) -> Unit) {
|
|
38
|
+
PushSignalCenter.setOnMessage(callback)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override fun setOnNotificationPress(callback: (message: PushMessage) -> Unit) {
|
|
42
|
+
PushSignalCenter.setOnNotificationPress(callback)
|
|
43
|
+
}
|
|
44
|
+
}
|