55 */
66
77import React , { Component } from 'react' ;
8- import {
9- AppRegistry ,
10- StyleSheet ,
11- View ,
12- Alert
13- } from 'react-native' ;
14-
15- import { Container , Content , Card , CardItem , Text } from 'native-base' ;
16- import Getui from 'react-native-getui'
17-
8+ import { AppRegistry , StyleSheet , View , Alert , Button } from 'react-native' ;
189
10+ import { Container , Content , Card , CardItem , Text } from 'native-base' ;
11+ import Getui from 'react-native-getui' ;
1912
2013export default class App extends Component {
21-
22- constructor ( props ) {
23- super ( props ) ;
24- // 初始状态
25- this . state = {
26- clientId : '' ,
27- version :'' ,
28- status :''
29- } ;
30-
31- }
32-
33- componentWillMount ( ) {
34-
35- this . updateComponentInfo ( )
36-
37- }
38- render ( ) {
39- return (
40- < View style = { styles . container } >
41- < Container >
42- < Content >
43- < Card >
44- < CardItem >
45- < Text >
46- Version : { this . state . version }
47- </ Text >
48- </ CardItem >
49- </ Card >
50- < Card >
51- < CardItem >
52- < Text >
53- ClientId : { this . state . clientId }
54- </ Text >
55- </ CardItem >
56- </ Card >
57- < Card >
58- < CardItem >
59- < Text >
60- 运行状态 : { this . state . status }
61- </ Text >
62- </ CardItem >
63- </ Card >
64-
65- </ Content >
66-
67- </ Container >
68- </ View >
69- ) ;
70- }
71-
72- componentDidMount ( ) {
73- this . updateComponentInfo ( )
74- }
75-
76- updateComponentInfo ( ) {
77-
78- Getui . clientId ( ( param ) => {
79- this . setState ( { 'clientId' : param } )
80- } )
81-
82- Getui . version ( ( param ) => {
83- this . setState ( { 'version' : param } )
84- } )
85-
86- Getui . status ( ( param ) => {
87- let status = ''
88- switch ( param ) {
89- case '0' :
90- status = '正在启动'
91- break ;
92- case '1' :
93- status = '启动'
94- break ;
95- case '2' :
96- status = '停止'
97- break ;
98- }
99- this . setState ( { 'status' : status } )
100- } )
101- }
102-
14+ constructor ( props ) {
15+ super ( props ) ;
16+ // 初始状态
17+ this . state = {
18+ clientId : '' ,
19+ version : '' ,
20+ status : '' ,
21+ } ;
22+ }
23+
24+ componentWillMount ( ) {
25+ this . updateComponentInfo ( ) ;
26+ }
27+
28+ handleTurnOn = ( ) => {
29+ Getui . turnOnPush ( ) ;
30+ } ;
31+
32+ handleTurnOff = ( ) => {
33+ Getui . turnOffPush ( ) ;
34+ } ;
35+
36+ render ( ) {
37+ return (
38+ < View style = { styles . container } >
39+ < Container >
40+ < Content >
41+ < Card >
42+ < CardItem >
43+ < Text > Version : { this . state . version } </ Text >
44+ </ CardItem >
45+ </ Card >
46+ < Card >
47+ < CardItem >
48+ < Text > ClientId : { this . state . clientId } </ Text >
49+ </ CardItem >
50+ </ Card >
51+ < Card >
52+ < CardItem >
53+ < Text > 运行状态 : { this . state . status } </ Text >
54+ </ CardItem >
55+ </ Card >
56+ </ Content >
57+ < View style = { { flex : 1 , flexDirection : 'row' , width : '100%' } } >
58+ < Button title = "turnOn" onPress = { this . handleTurnOn } />
59+ < Button title = "turnOff" onPress = { this . handleTurnOff } />
60+ </ View >
61+ </ Container >
62+ </ View >
63+ ) ;
64+ }
65+
66+ componentDidMount ( ) {
67+ this . updateComponentInfo ( ) ;
68+ }
69+
70+ updateComponentInfo ( ) {
71+ Getui . clientId ( ( param ) => {
72+ this . setState ( { clientId : param } ) ;
73+ } ) ;
74+
75+ Getui . version ( ( param ) => {
76+ this . setState ( { version : param } ) ;
77+ } ) ;
78+
79+ Getui . status ( ( param ) => {
80+ let status = '' ;
81+ switch ( param ) {
82+ case '0' :
83+ status = '正在启动' ;
84+ break ;
85+ case '1' :
86+ status = '启动' ;
87+ break ;
88+ case '2' :
89+ status = '停止' ;
90+ break ;
91+ }
92+ this . setState ( { status : status } ) ;
93+ } ) ;
94+ }
10395}
10496
10597const styles = StyleSheet . create ( {
106- container : {
107- flex : 1 ,
108- justifyContent : 'center' ,
109- alignItems : 'center' ,
110- backgroundColor : '#F5FCFF' ,
111- marginTop :20
112- } ,
113- content : {
114- marginTop : 60
115- }
98+ container : {
99+ flex : 1 ,
100+ justifyContent : 'center' ,
101+ alignItems : 'center' ,
102+ backgroundColor : '#F5FCFF' ,
103+ marginTop : 20 ,
104+ } ,
105+ content : {
106+ marginTop : 60 ,
107+ } ,
116108} ) ;
117109
118110//订阅消息通知
119111var { NativeAppEventEmitter } = require ( 'react-native' ) ;
120112
121- var receiveRemoteNotificationSub = NativeAppEventEmitter . addListener (
122- 'receiveRemoteNotification' ,
123- ( notification ) => {
124- //Android的消息类型为payload 透传消息 或者 cmd消息
125- switch ( notification . type ) {
126- case "cid" :
127- // console.log("receiveRemoteNotification cid = " + notification.cid)
128- Alert . alert ( '初始化获取到cid' , JSON . stringify ( notification ) )
129- break ;
130- case 'payload' :
131- Alert . alert ( 'payload 消息通知' , JSON . stringify ( notification ) )
132- break
133- case 'cmd' :
134- Alert . alert ( 'cmd 消息通知' , 'cmd action = ' + notification . cmd )
135- break
136- case 'notificationArrived' :
137- Alert . alert ( 'notificationArrived 通知到达' , JSON . stringify ( notification ) )
138- break
139- case 'notificationClicked' :
140- Alert . alert ( 'notificationArrived 通知点击' , JSON . stringify ( notification ) )
141- break
142- default :
143- }
144- }
145- ) ;
146-
147- var clickRemoteNotificationSub = NativeAppEventEmitter . addListener (
148- 'clickRemoteNotification' ,
149- ( notification ) => {
150- Alert . alert ( '点击通知' , JSON . stringify ( notification ) )
151- }
152- ) ;
113+ var receiveRemoteNotificationSub = NativeAppEventEmitter . addListener (
114+ 'receiveRemoteNotification' ,
115+ ( notification ) => {
116+ //Android的消息类型为payload 透传消息 或者 cmd消息
117+ switch ( notification . type ) {
118+ case 'cid' :
119+ // console.log("receiveRemoteNotification cid = " + notification.cid)
120+ Alert . alert ( '初始化获取到cid' , JSON . stringify ( notification ) ) ;
121+ break ;
122+ case 'payload' :
123+ Alert . alert ( 'payload 消息通知' , JSON . stringify ( notification ) ) ;
124+ break ;
125+ case 'cmd' :
126+ Alert . alert ( 'cmd 消息通知' , 'cmd action = ' + notification . cmd ) ;
127+ break ;
128+ case 'notificationArrived' :
129+ Alert . alert (
130+ 'notificationArrived 通知到达' ,
131+ JSON . stringify ( notification )
132+ ) ;
133+ break ;
134+ case 'notificationClicked' :
135+ Alert . alert (
136+ 'notificationArrived 通知点击' ,
137+ JSON . stringify ( notification )
138+ ) ;
139+ break ;
140+ default :
141+ }
142+ }
143+ ) ;
144+
145+ var clickRemoteNotificationSub = NativeAppEventEmitter . addListener (
146+ 'clickRemoteNotification' ,
147+ ( notification ) => {
148+ Alert . alert ( '点击通知' , JSON . stringify ( notification ) ) ;
149+ }
150+ ) ;
0 commit comments