-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (47 loc) · 1.81 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import OneSignal from 'react-native-onesignal';
import {AppRegistry} from 'react-native';
import App, {navigationRef} from './src/App';
import {name as appName} from './app.json';
import {getAndOrFetchConversationById} from './src/services/conversation';
// /!/ removing this import causes errors
import * as encoding from 'text-encoding';
//OneSignal Init Code
OneSignal.setLogLevel(6, 0);
OneSignal.setAppId('d3d8d445-1cc5-4c20-8d1d-ea494369b2c9');
//END OneSignal Init Code
//Prompt for push on iOS
OneSignal.promptForPushNotificationsWithUserResponse(response => {
console.log('Prompt response:', response);
});
//Method for handling notifications received while app in foreground
OneSignal.setNotificationWillShowInForegroundHandler(
notificationReceivedEvent => {
notificationReceivedEvent.complete(null);
//notificationReceivedEvent.complete(notification);
},
);
//Method for handling notifications opened
OneSignal.setNotificationOpenedHandler(notification => {
const data = notification.notification.additionalData;
// Get information about the conversationId
if (data) {
const conversationId = data.conversation_id;
navigationRef.current.navigate('Inbox');
getAndOrFetchConversationById(conversationId)
.then(conversation => {
navigationRef.current.navigate('MessageList', {
conversationId,
avatarUrl: conversation.metadata.contact.avatarUrl,
displayName: conversation.metadata.contact.displayName,
state: conversation.metadata.state,
source: conversation.channel.source,
sourceChannelId: conversation.channel.sourceChannelId,
metadataName: conversation.channel.metadata.name,
});
})
.catch(error => {
console.error(error);
});
}
});
AppRegistry.registerComponent(appName, () => App);