notifly-sdk 1.0.6 → 1.0.8

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 (2) hide show
  1. package/index.js +20 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import messaging from "@react-native-firebase/messaging";
2
- import { Linking, Platform } from 'react-native';
2
+ import { Linking, PermissionsAndroid, Platform } from 'react-native';
3
3
  import AsyncStorage from '@react-native-async-storage/async-storage';
4
4
  import rnDeviceInfo from 'react-native-device-info';
5
5
  import { v5 } from 'uuid';
@@ -24,7 +24,7 @@ exports.setUserId = async function (userID) {
24
24
  }
25
25
  }
26
26
 
27
- exports.sessionStart = async function () {
27
+ async function _sessionStart() {
28
28
  const apiLevel = rnDeviceInfo.getApiLevel(); // only android
29
29
  const brand = rnDeviceInfo.getBrand(); // apple samsung
30
30
  const model = rnDeviceInfo.getModel(); // 기종 SM-G960N or iPhone 8
@@ -41,9 +41,20 @@ exports.sessionStart = async function () {
41
41
  await logEvent("session_start", openAppEventParams, null, true)
42
42
  }
43
43
 
44
- exports.initialize = async function (prjId, userName, password) {
44
+ exports.initialize = function (prjId, userName, password) {
45
+ _initialize(prjId, userName, password);
46
+ }
47
+
48
+ function _initialize(prjId, userName, password) {
45
49
  try {
50
+
51
+ await messaging().requestPermission();
52
+
46
53
  messaging().onNotificationOpenedApp(async (remoteMessage) => {
54
+ const link = remoteMessage.data?.link
55
+ if (link) {
56
+ Linking.openURL(link);
57
+ }
47
58
  await logEvent("push_click", { "campaign_id": remoteMessage.data.campaign_id, "status": "background" }, null, true);
48
59
  });
49
60
 
@@ -53,9 +64,9 @@ exports.initialize = async function (prjId, userName, password) {
53
64
  .getInitialNotification()
54
65
  .then(async (remoteMessage) => {
55
66
  if (remoteMessage) {
56
- const link = remoteMessage.notification?.android?.link;
67
+ const link = remoteMessage.data?.link
57
68
  if (link) {
58
- Linking.openURL(remoteMessage.notification?.android?.link);
69
+ Linking.openURL(link);
59
70
  }
60
71
  await logEvent("push_click", { "campaign_id": remoteMessage.data.campaign_id, "status": "quit" }, null, true);
61
72
  }
@@ -66,6 +77,9 @@ exports.initialize = async function (prjId, userName, password) {
66
77
  AsyncStorage.setItem('notiflyUserName', userName),
67
78
  AsyncStorage.setItem('notiflyUserPassword', password),
68
79
  ])
80
+
81
+ await _sessionStart();
82
+
69
83
  } catch (err) {
70
84
  console.warn("[Notifly]: ", err);
71
85
  }
@@ -221,6 +235,7 @@ async function logEvent(eventName, eventParams, segmentation_event_param_keys =
221
235
 
222
236
  const response = await _apiCall("https://12lnng07q2.execute-api.ap-northeast-2.amazonaws.com/prod/records", requestOptions);
223
237
  const result = JSON.parse(response)
238
+ console.log('api', result)
224
239
  if (result.message == "The incoming token has expired") {
225
240
  const [userName, password] = await Promise.all([AsyncStorage.getItem('notiflyUserName'), AsyncStorage.getItem('notiflyUserPassword')])
226
241
  const newToken = await getCognitoIdToken(userName, password);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notifly-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {