-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (28 loc) · 1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @format
*/
import {AppRegistry, Linking} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import PushNotification from 'react-native-push-notification';
PushNotification.configure({
// Must be outside of any component LifeCycle (such as `componentDidMount`).
// (required) Called when a remote is received or opened, or local notification is opened
onNotification: async function (remoteMessage) {
console.log('NOTIFICATION:', remoteMessage);
if (remoteMessage.data?.redirect_to) {
const can_open_url = await Linking.canOpenURL(
remoteMessage.data.redirect_to,
);
if (can_open_url) {
console.log('Opening url - ', remoteMessage.data.redirect_to);
await Linking.openURL(remoteMessage.data.redirect_to).catch(err => {
console.log(err);
});
} else {
console.log("Can't open url - ", remoteMessage.data.redirect_to);
}
}
},
});
AppRegistry.registerComponent(appName, () => App);