-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
60 lines (54 loc) · 2.55 KB
/
App.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
54
55
56
57
58
59
60
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { applyMiddleware, createStore } from 'redux';
import { persistStore, } from 'redux-persist';
import { PersistGate } from 'redux-persist/es/integration/react';
import ReduxThunk from 'redux-thunk';
import rootReducer from './src/reducers/rootReducer';
import RouterComp from './src/router';
import OneSignal from 'react-native-onesignal'; // Import package from node modules
import {AsyncStorage } from 'react-native';
import { PhoneHeight } from './src/components/config/env';
export default class App extends Component {
constructor(properties) {
super(properties);
//Remove this method to stop OneSignal Debugging
OneSignal.setLogLevel(6, 0)
// Replace 'YOUR_ONESIGNAL_APP_ID' with your OneSignal App ID.
OneSignal.init("85709f52-b07d-4e2b-8a75-6703178bb15a", {kOSSettingsKeyAutoPrompt : false, kOSSettingsKeyInAppLaunchURL: false, kOSSettingsKeyInFocusDisplayOption:2});
OneSignal.inFocusDisplaying(2); // Controls what should happen if a notification is received while the app is open. 2 means that the notification will go directly to the device's notification center.
// The promptForPushNotifications function code will show the iOS push notification prompt. We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step below)
OneSignal.promptForPushNotificationsWithUserResponse(this.myiOSPromptCallback);
OneSignal.addEventListener('received', this.onReceived);
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('ids', this.onIds);
}
onReceived(notification) {
console.log("Notification received: ", notification);
}
myiOSPromptCallback(permission){
// do something with permission value
}
onOpened(openResult) {
console.log('Message: ', openResult.notification.payload.body);
console.log('Data: ', openResult.notification.payload.additionalData);
console.log('isActive: ', openResult.notification.isAppInFocus);
console.log('openResult: ', openResult);
}
onIds(device) {
const phoneToken = device.userId;
AsyncStorage.setItem("device",phoneToken )
console.log('Device info: ', phoneToken);
}
render() {
const store = createStore(rootReducer, {}, applyMiddleware(ReduxThunk))
const persisStore = persistStore(store)
return (
<Provider store={store}>
<PersistGate persistor={persisStore} loading={null}>
<RouterComp />
</PersistGate>
</Provider>
)
}
}