|
| 1 | +import React from 'react'; |
| 2 | +import {StyleSheet, Text, View, TouchableHighlight} from 'react-native'; |
| 3 | +import JPush from 'jpush-react-native'; |
| 4 | + |
| 5 | +const styles = StyleSheet.create({ |
| 6 | + container: { |
| 7 | + flex: 1, |
| 8 | + justifyContent: 'center', |
| 9 | + alignItems: 'center', |
| 10 | + backgroundColor: '#F5FCFF', |
| 11 | + }, |
| 12 | + setBtnStyle: { |
| 13 | + width: 320, |
| 14 | + justifyContent: 'center', |
| 15 | + alignItems: 'center', |
| 16 | + marginTop: 10, |
| 17 | + borderWidth: 1, |
| 18 | + borderColor: '#3e83d7', |
| 19 | + borderRadius: 8, |
| 20 | + backgroundColor: '#3e83d7', |
| 21 | + padding: 10 |
| 22 | + }, |
| 23 | + textStyle: { |
| 24 | + textAlign: 'center', |
| 25 | + fontSize: 25, |
| 26 | + color: '#ffffff' |
| 27 | + } |
| 28 | +}); |
| 29 | + |
| 30 | +class Button extends React.Component { |
| 31 | + render() { |
| 32 | + return <TouchableHighlight |
| 33 | + onPress={this.props.onPress} |
| 34 | + underlayColor='#e4083f' |
| 35 | + activeOpacity={0.5} |
| 36 | + > |
| 37 | + <View |
| 38 | + style={styles.setBtnStyle}> |
| 39 | + <Text |
| 40 | + style={styles.textStyle}> |
| 41 | + {this.props.title} |
| 42 | + </Text> |
| 43 | + </View> |
| 44 | + </TouchableHighlight> |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +export default class App extends React.Component { |
| 49 | + |
| 50 | + constructor(props) { |
| 51 | + super(props); |
| 52 | + } |
| 53 | + |
| 54 | + componentDidMount() { |
| 55 | + JPush.init({"appKey":"4fcc3e237eec4c4fb804ad49","channel":"dev","production":1}); |
| 56 | + //连接状态 |
| 57 | + this.connectListener = result => { |
| 58 | + console.log("connectListener:" + JSON.stringify(result)) |
| 59 | + }; |
| 60 | + JPush.addConnectEventListener(this.connectListener); |
| 61 | + //通知回调 |
| 62 | + this.notificationListener = result => { |
| 63 | + console.log("notificationListener:" + JSON.stringify(result)) |
| 64 | + alert(JSON.stringify(result)) |
| 65 | + }; |
| 66 | + JPush.addNotificationListener(this.notificationListener); |
| 67 | + //本地通知回调 |
| 68 | + this.localNotificationListener = result => { |
| 69 | + console.log("localNotificationListener:" + JSON.stringify(result)) |
| 70 | + }; |
| 71 | + JPush.addLocalNotificationListener(this.localNotificationListener); |
| 72 | + //自定义消息回调 |
| 73 | + this.customMessageListener = result => { |
| 74 | + console.log("customMessageListener:" + JSON.stringify(result)) |
| 75 | + }; |
| 76 | + JPush.addCustomMessageListener(this.customMessageListener); |
| 77 | + //应用内消息回调 |
| 78 | + JPush.pageEnterTo("HomePage") // 进入首页,当页面退出时请调用 JPush.pageLeave('HomePage') |
| 79 | + this.inappMessageListener = result => { |
| 80 | + console.log("inappMessageListener:" + JSON.stringify(result)) |
| 81 | + alert(JSON.stringify(result)) |
| 82 | + }; |
| 83 | + JPush.addInappMessageListener(this.inappMessageListener); |
| 84 | + //tag alias事件回调 |
| 85 | + this.tagAliasListener = result => { |
| 86 | + console.log("tagAliasListener:" + JSON.stringify(result)) |
| 87 | + }; |
| 88 | + JPush.addTagAliasListener(this.tagAliasListener); |
| 89 | + //手机号码事件回调 |
| 90 | + this.mobileNumberListener = result => { |
| 91 | + console.log("mobileNumberListener:" + JSON.stringify(result)) |
| 92 | + }; |
| 93 | + JPush.addMobileNumberListener(this.mobileNumberListener); |
| 94 | + } |
| 95 | + |
| 96 | + render() { |
| 97 | + return ( |
| 98 | + <View style={styles.container}> |
| 99 | + <Button title="setLoggerEnable" |
| 100 | + onPress={() => JPush.setLoggerEnable(true) |
| 101 | + }/> |
| 102 | + |
| 103 | + <Button title="getRegisterID" |
| 104 | + onPress={() => JPush.getRegistrationID(result => |
| 105 | + console.log("registerID:" + JSON.stringify(result)) |
| 106 | + )}/> |
| 107 | + |
| 108 | + <Button title="设置用户属性" |
| 109 | + onPress={() => JPush.setProperties({sequence: 1, pros:{2:'b'}})}/> |
| 110 | + {/*<Button title="addTags" |
| 111 | + onPress={() => JPush.addTags({sequence: 1, tags: ["1", "2", "3"]})}/> |
| 112 | +
|
| 113 | + <Button title="updateTags" |
| 114 | + onPress={() => JPush.updateTags({sequence: 2, tags: ["4", "5", "6"]})}/> |
| 115 | +
|
| 116 | + <Button title="deleteTag" |
| 117 | + onPress={() => JPush.deleteTag({sequence: 3, tags: ["4", "5", "6"]})}/> |
| 118 | +
|
| 119 | + <Button title="deleteTags" |
| 120 | + onPress={() => JPush.deleteTags({sequence: 4})}/> |
| 121 | +
|
| 122 | + <Button title="queryTag" |
| 123 | + onPress={() => JPush.queryTag({sequence: 4, tag: "1"})}/> |
| 124 | +
|
| 125 | + <Button title="queryTags" |
| 126 | + onPress={() => JPush.queryTags({sequence: 5})}/> |
| 127 | +
|
| 128 | + <Button title="setAlias" |
| 129 | + onPress={() => JPush.setAlias({sequence: 6,alias:"xxx"})}/> |
| 130 | +
|
| 131 | + <Button title="deleteAlias" |
| 132 | + onPress={() => JPush.deleteAlias({sequence: 7})}/> |
| 133 | +
|
| 134 | + <Button title="queryAlias" |
| 135 | + onPress={() => JPush.queryAlias({sequence: 8})}/> |
| 136 | +
|
| 137 | + <Button title="setMobileNumber" |
| 138 | + onPress={() => JPush.setMobileNumber({mobileNumber: "13888888888"})}/> |
| 139 | +
|
| 140 | + //仅ios |
| 141 | + <Button title="setBadge" |
| 142 | + onPress={() => JPush.setBadge({"badge":1,"appBadge":1})}/> |
| 143 | +
|
| 144 | + <Button title="initCrashHandler" |
| 145 | + onPress={() => JPush.initCrashHandler()}/> |
| 146 | +
|
| 147 | + <Button title="addLocalNotification" |
| 148 | + onPress={() => JPush.addLocalNotification({ |
| 149 | + messageID: "123456789", |
| 150 | + title: "title123", |
| 151 | + content: "content123", |
| 152 | + extras: {"key123": "value123"} |
| 153 | + })}/> |
| 154 | +
|
| 155 | + <Button title="removeLocalNotification" |
| 156 | + onPress={() => JPush.removeLocalNotification({messageID: '123456789'})}/>*/} |
| 157 | + |
| 158 | + </View> |
| 159 | + ); |
| 160 | + } |
| 161 | + |
| 162 | +} |
| 163 | + |
| 164 | + |
| 165 | + |
0 commit comments