This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.ios.js
86 lines (78 loc) · 2.25 KB
/
index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
import {
NativeModules,
NativeAppEventEmitter
} from 'react-native';
var XG = NativeModules.TencentXG;
var disableIOS;
function allEvents() {
return [
XG.RemoteNotificationEvent,
XG.RegisteredEvent,
XG.FailureEvent
];
}
function eventHandle(event, listener, dataBack) {
var data = dataBack;
if (event === XG.RemoteNotificationEvent) {
if (dataBack.aps) {
data = {};
data.alertBody = dataBack.aps.alert;
data.badge = dataBack.aps.badge;
Object.keys(dataBack).filter(k => k !== 'aps')
.forEach(k => data[k] = dataBack[k]);
}
}
listener(data);
}
function addEventListener(event, listener) {
if (disableIOS) return disableIOS;
if (allEvents().indexOf(event) < 0) return;
return NativeAppEventEmitter.addListener(
event, eventHandle.bind(null, event, listener)
);
}
function scheduleLocalNotification(obj) {
if (disableIOS) return;
if (obj.fireDate) {
XG.scheduleLocalNotification(obj);
} else {
XG.presentLocalNotification(obj);
}
}
module.exports = {
addEventListener,
allEvents,
scheduleLocalNotification,
disableIOS: disabled => disableIOS = (disabled === undefined ? true : disabled),
enableDebug: enable => {
return disableIOS || XG.enableDebug(enable === undefined ? true : enable);
},
setCredential: (accessId, accessKey) => {
return disableIOS || XG.setCredential(accessId, accessKey);
},
register: (account, permissions) => {
return disableIOS || XG.register(account, permissions);
},
checkPermissions: () => {
if (disableIOS) return Promise.resolve(disableIOS);
return XG.checkPermissions();
},
getApplicationIconBadgeNumber: () => {
if (disableIOS) return Promise.resolve();
return XG.getApplicationIconBadgeNumber();
},
setApplicationIconBadgeNumber: number => {
if (disableIOS) return;
return XG.setApplicationIconBadgeNumber(number);
},
cancelLocalNotifications: userInfo => {
return disableIOS || XG.cancelLocalNotifications(userInfo);
},
cancelAllLocalNotifications: () => {
return disableIOS || XG.cancelAllLocalNotifications();
},
setTag: tag => disableIOS || XG.setTag(tag),
delTag: tag => disableIOS || XG.delTag(tag),
unregister: () => disableIOS || XG.unRegisterDevice(),
};