-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathRemotePushIOS.js
45 lines (37 loc) · 1.29 KB
/
RemotePushIOS.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
var React = require("react-native");
var {
NativeModules,
DeviceEventEmitter
} = React;
const REGISTERED_FOR_REMOTE = "registeredForRemoteNotifications";
const REGISTERED_FOR_REMOTE_ERROR = "registeredForRemoteNotificationsError";
const RECEIVED_REMOTE = "receivedRemoteNotification";
module.exports = {
requestPermissions: function(callback) {
NativeModules.RemotePushManager.requestPermissions();
DeviceEventEmitter.addListener(
REGISTERED_FOR_REMOTE, function(notification) {
callback(null, notification);
}
);
DeviceEventEmitter.addListener(
REGISTERED_FOR_REMOTE_ERROR, function(error) {
callback("Couldn't register for notifications");
}
)
},
setListenerForNotifications: function(callback) {
NativeModules.RemotePushManager.getStartupNotifications(function(err, startupNotification) {
if (startupNotification) {
startupNotification.startup = true;
callback(startupNotification);
}
});
DeviceEventEmitter.addListener(
RECEIVED_REMOTE, function(notification) {
notification.startup = false;
callback(notification);
}
);
}
};