forked from voximplant/react-native-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PushManager.ios.js
66 lines (53 loc) · 1.88 KB
/
PushManager.ios.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
61
62
63
64
65
66
/*
* Copyright (c) 2011-2018, Zingaya, Inc. All rights reserved.
*/
'use strict';
import React from 'react';
import {
Platform
} from 'react-native';
import loginManager from './LoginManager';
import VoxImplant from 'react-native-voximplant';
import NotificationsIOS from 'react-native-notifications';
var pushToken = '';
class PushManager {
constructor() {
console.log("Push manager ios");
NotificationsIOS.consumeBackgroundQueue();
NotificationsIOS.addEventListener('pushKitRegistered', this.onPushKitRegistered.bind(this));
NotificationsIOS.registerPushKit();
NotificationsIOS.addEventListener('notificationReceivedBackground', this.onNotificationReceivedBackground.bind(this));
NotificationsIOS.addEventListener('notificationReceivedForeground', this.onNotificationReceivedForeground.bind(this));
}
init() {
console.log("PushManager init");
}
onPushKitRegistered(deviceToken) {
console.log("PushKit Token Received: " + deviceToken);
pushToken = deviceToken;
}
getPushToken() {
return pushToken;
}
pushNotificationReceived(notification) {
loginManager.getInstance().pushNotificationReceived(notification);
}
onNotificationReceivedForeground(notification) {
console.log("Notification Received Foreground: " + notification.getData());
loginManager.getInstance().pushNotificationReceived(notification.getData());
}
onNotificationReceivedBackground(notification) {
console.log("Notification Received Background: " + notification.getData());
loginManager.getInstance().pushNotificationReceived(notification.getData());
}
showLocalNotification(from) {
let localNotification = NotificationsIOS.localNotification({
alertBody: "from: " + from,
alertTitle: "Incoming call",
soundName: "chime.aiff",
silent: false
});
}
}
const pushManager = new PushManager();
export default pushManager;