-
Notifications
You must be signed in to change notification settings - Fork 339
/
App.js
152 lines (129 loc) · 5.19 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import React from 'react';
import {StyleSheet, Text, View, TouchableHighlight} from 'react-native';
import JPush from 'jpush-react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
setBtnStyle: {
width: 320,
justifyContent: 'center',
alignItems: 'center',
marginTop: 10,
borderWidth: 1,
borderColor: '#3e83d7',
borderRadius: 8,
backgroundColor: '#3e83d7',
padding: 10
},
textStyle: {
textAlign: 'center',
fontSize: 25,
color: '#ffffff'
}
});
class Button extends React.Component {
render() {
return <TouchableHighlight
onPress={this.props.onPress}
underlayColor='#e4083f'
activeOpacity={0.5}
>
<View
style={styles.setBtnStyle}>
<Text
style={styles.textStyle}>
{this.props.title}
</Text>
</View>
</TouchableHighlight>
}
}
export default class App extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
JPush.init({"appKey":"02c7f79c9248ecadf25140f7","channel":"dev","production":1});
//连接状态
this.connectListener = result => {
console.log("connectListener:" + JSON.stringify(result))
};
JPush.addConnectEventListener(this.connectListener);
//通知回调
this.notificationListener = result => {
console.log("notificationListener:" + JSON.stringify(result))
};
JPush.addNotificationListener(this.notificationListener);
//本地通知回调
this.localNotificationListener = result => {
console.log("localNotificationListener:" + JSON.stringify(result))
};
JPush.addLocalNotificationListener(this.localNotificationListener);
//自定义消息回调
// this.customMessageListener = result => {
// console.log("customMessageListener:" + JSON.stringify(result))
// };
// JPush.addCustomMessagegListener(this.customMessageListener);
//tag alias事件回调
this.tagAliasListener = result => {
console.log("tagAliasListener:" + JSON.stringify(result))
};
JPush.addTagAliasListener(this.tagAliasListener);
//手机号码事件回调
this.mobileNumberListener = result => {
console.log("mobileNumberListener:" + JSON.stringify(result))
};
JPush.addMobileNumberListener(this.mobileNumberListener);
}
render() {
return (
<View style={styles.container}>
<Button title="setLoggerEnable"
onPress={() => JPush.setLoggerEnable(true)
}/>
<Button title="getRegisterID"
onPress={() => JPush.getRegistrationID(result =>
console.log("registerID:" + JSON.stringify(result))
)}/>
{/*<Button title="addTags"
onPress={() => JPush.addTags({sequence: 1, tags: ["1", "2", "3"]})}/>
<Button title="updateTags"
onPress={() => JPush.updateTags({sequence: 2, tags: ["4", "5", "6"]})}/>
<Button title="deleteTag"
onPress={() => JPush.deleteTag({sequence: 3, tags: ["4", "5", "6"]})}/>
<Button title="deleteTags"
onPress={() => JPush.deleteTags({sequence: 4})}/>
<Button title="queryTag"
onPress={() => JPush.queryTag({sequence: 4, tag: "1"})}/>
<Button title="queryTags"
onPress={() => JPush.queryTags({sequence: 5})}/>
<Button title="setAlias"
onPress={() => JPush.setAlias({sequence: 6,alias:"xxx"})}/>
<Button title="deleteAlias"
onPress={() => JPush.deleteAlias({sequence: 7})}/>
<Button title="queryAlias"
onPress={() => JPush.queryAlias({sequence: 8})}/>
<Button title="setMobileNumber"
onPress={() => JPush.setMobileNumber({mobileNumber: "13888888888"})}/>
//仅ios
<Button title="setBadge"
onPress={() => JPush.setBadge({"badge":1,"appBadge":1})}/>
<Button title="initCrashHandler"
onPress={() => JPush.initCrashHandler()}/>
<Button title="addLocalNotification"
onPress={() => JPush.addLocalNotification({
messageID: "123456789",
title: "title123",
content: "content123",
extras: {"key123": "value123"}
})}/>
<Button title="removeLocalNotification"
onPress={() => JPush.removeLocalNotification({messageID: '123456789'})}/>*/}
</View>
);
}
}