-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
42 lines (35 loc) · 1.23 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
import {
NativeModules,
DeviceEventEmitter,
NativeEventEmitter,
Platform,
} from 'react-native';
const eventsMap = {
remoteNotificationReceived: 'remoteNotificationReceived',
localNotificationReceived: 'localNotificationReceived',
aliMessageReceived: 'aliMessageReceived',
registerUserNotificationSettings: 'registerUserNotificationSettings',
};
const AliPushManager = NativeModules.AliPushManager;
const AliPush = {};
AliPush.requestPermissions = (permissions=null) => {
return AliPushManager.requestPermissions(permissions);
};
AliPush.setApplicationIconBadgeNumber = AliPushManager.setApplicationIconBadgeNumber;
AliPush.bindAccount = AliPushManager.bindAccount;
AliPush.unbindAccount = AliPushManager.unbindAccount;
AliPush.getInitialNotification = AliPushManager.getInitialNotification;
const AliPushEmitter = new NativeEventEmitter(AliPushManager);
AliPush.on = (event,callback) => {
const nativeEvent = eventsMap[event];
if (!nativeEvent) {
var s = ""
for(var key in eventsMap){
s+= key +","
}
throw new Error('event must in "'+s);
}
const listener = AliPushEmitter.addListener(nativeEvent,callback);
return listener;
};
module.exports = AliPush;