@inngageregistry/inngage-react 3.0.5 → 3.0.6
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/README.md +40 -0
- package/package.json +6 -6
- package/src/Inngage.ts +41 -30
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<b>
|
|
3
|
+
<a href="https://inngage.com.br/"><img src="https://inngage.com.br/wp-content/uploads/2022/03/inngage-small.png" /></a><br>
|
|
4
|
+
</b>
|
|
5
|
+
</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">Pacote Inngage para aplicativos React Native para otimização de campanhas de marketing usando notificações push.</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://inngage.com.br/"><b>Website</b></a> •
|
|
11
|
+
<a href="https://inngage.readme.io/docs/react-native-sdk-20"><b>Documentation</b></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<div align="center">
|
|
15
|
+
|
|
16
|
+
[](https://www.npmjs.org/package/@inngageregistry/inngage-react)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
## Instalação
|
|
21
|
+
### Instalando as dependências
|
|
22
|
+
```bash
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@react-native-async-storage/async-storage": "^1.18.1",
|
|
25
|
+
"@react-native-firebase/app": "^17.4.2",
|
|
26
|
+
"@react-native-firebase/messaging": "^17.4.2",
|
|
27
|
+
"react-native-device-info": "^10.6.0",
|
|
28
|
+
"react-native-inappbrowser-reborn": "^3.7.0",
|
|
29
|
+
"react-native-localize": "^2.2.6",
|
|
30
|
+
"react-native-snap-carousel": "^3.9.1"
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
Ao adicioná-las no seu ```package.json```, utilize o comando ```npm install```.
|
|
34
|
+
### Importar FCM Token (API Key)
|
|
35
|
+
Para aproveitar nossos SDKs, será necessário importar o FCM Token (API Key) do seu projeto Firebase em nossa plataforma.
|
|
36
|
+
### Instalando a SDK
|
|
37
|
+
Utilize o NPM:
|
|
38
|
+
```bash
|
|
39
|
+
$ npm i @inngageregistry/inngage-react
|
|
40
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inngageregistry/inngage-react",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "Inngage Plugin for React Native applications for marketing campaign optimization using Push Notification.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/inngage/inngage-react#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@react-native-async-storage/async-storage": "^1.18.1",
|
|
23
|
+
"@react-native-community/push-notification-ios": "^1.11.0",
|
|
22
24
|
"@react-native-firebase/app": "^17.4.2",
|
|
23
25
|
"@react-native-firebase/messaging": "^17.4.2",
|
|
24
|
-
"react-native-
|
|
25
|
-
"react-native-snap-carousel": "^3.9.1",
|
|
26
|
-
"@react-native-async-storage/async-storage": "^1.18.1",
|
|
26
|
+
"react-native-device-info": "^10.6.0",
|
|
27
27
|
"react-native-inappbrowser-reborn": "^3.7.0",
|
|
28
|
-
"
|
|
28
|
+
"react-native-localize": "^2.2.6",
|
|
29
29
|
"react-native-push-notification": "^8.1.1",
|
|
30
|
-
"react-native-
|
|
30
|
+
"react-native-snap-carousel": "^3.9.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/jest": "^29.5.1",
|
package/src/Inngage.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Platform,
|
|
3
|
+
PermissionsAndroid,
|
|
3
4
|
LogBox,
|
|
4
5
|
AppRegistry,
|
|
5
6
|
} from "react-native";
|
|
@@ -30,39 +31,49 @@ const backgroundNotificationHandler = async remoteMessage => {
|
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
// --- Get Firebase Access ------/
|
|
33
|
-
const getFirebaseAccess = () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
const getFirebaseAccess = async (): Promise<string | null> => {
|
|
35
|
+
try {
|
|
36
|
+
const apiLevel = await DeviceInfo.getApiLevel();
|
|
37
|
+
|
|
38
|
+
if (apiLevel >= 33) {
|
|
39
|
+
await PermissionsAndroid.request(
|
|
40
|
+
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const authStatus = await firebase.messaging().requestPermission();
|
|
45
|
+
|
|
46
|
+
const enabled =
|
|
47
|
+
authStatus === firebase.messaging.AuthorizationStatus.AUTHORIZED ||
|
|
48
|
+
authStatus === firebase.messaging.AuthorizationStatus.PROVISIONAL;
|
|
49
|
+
|
|
50
|
+
if (enabled) {
|
|
51
|
+
let fcmToken = await AsyncStorage.getItem('fcmToken');
|
|
52
|
+
console.log('Old token: ', fcmToken);
|
|
53
|
+
|
|
54
|
+
if (!fcmToken) {
|
|
55
|
+
if (!firebase.messaging().isDeviceRegisteredForRemoteMessages) {
|
|
56
|
+
await firebase.messaging().registerDeviceForRemoteMessages();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const newFcmToken = await firebase.messaging().getToken();
|
|
60
|
+
|
|
61
|
+
if (newFcmToken) {
|
|
62
|
+
await AsyncStorage.setItem('fcmToken', newFcmToken);
|
|
63
|
+
console.log('New token: ', newFcmToken);
|
|
64
|
+
return newFcmToken;
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
console.error(error)
|
|
58
|
-
return resolve(firebaseToken)
|
|
59
|
-
}
|
|
60
|
-
return resolve(firebaseToken)
|
|
61
|
-
} catch (err) {
|
|
62
|
-
console.error(err)
|
|
63
|
-
return resolve(firebaseToken)
|
|
67
|
+
|
|
68
|
+
console.log('Authorization status:', authStatus);
|
|
69
|
+
return fcmToken;
|
|
64
70
|
}
|
|
65
|
-
|
|
71
|
+
|
|
72
|
+
return null;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.log('Erro no getFirebaseAccess: ', error);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
66
77
|
};
|
|
67
78
|
|
|
68
79
|
interface SubscriptionProps {
|