|
@@ -5,13 +5,15 @@ import PushNotification from "react-native-push-notification";
|
|
|
import Dialog from '../../components/Dialog';
|
|
import Dialog from '../../components/Dialog';
|
|
|
import apiUpload from '../../api/apiUpload';
|
|
import apiUpload from '../../api/apiUpload';
|
|
|
import app from '../../../app.json'
|
|
import app from '../../../app.json'
|
|
|
|
|
+import utils from '../../utils/utils';
|
|
|
|
|
|
|
|
export default class Notify extends Component {
|
|
export default class Notify extends Component {
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
|
this.state = {
|
|
this.state = {
|
|
|
permission: false,
|
|
permission: false,
|
|
|
- notifyToken: 'none'
|
|
|
|
|
|
|
+ notifyToken: '',
|
|
|
|
|
+ serverToken: ''
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -22,6 +24,18 @@ export default class Notify extends Component {
|
|
|
notifyToken: global.notifyToken.token
|
|
notifyToken: global.notifyToken.token
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
+ this.getUserToken();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getUserToken() {
|
|
|
|
|
+ getUserInfo(info => {
|
|
|
|
|
+ if (info.firebaseToken) {
|
|
|
|
|
+ let token = isIOS ? info.firebaseToken?.ios : info.firebaseToken?.android
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ serverToken: token ?? ""
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async requestUserPermission() {
|
|
async requestUserPermission() {
|
|
@@ -79,36 +93,65 @@ export default class Notify extends Component {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ updateToken() {
|
|
|
|
|
+ if (getUserId() > 0) {
|
|
|
|
|
+ Dialog.showProgressDialog();
|
|
|
|
|
+ utils.registerFirebaseToken("", res => {
|
|
|
|
|
+ Dialog.dismissLoading();
|
|
|
|
|
+ toastShort(res ? "Upload success" : "Upload failed")
|
|
|
|
|
+ if (res) {
|
|
|
|
|
+ this.getUserToken();
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ toastShort("Please login first");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
copyToken() {
|
|
copyToken() {
|
|
|
- Clipboard.setString(this.state.notifyToken);
|
|
|
|
|
- toastShort('已复制到剪贴板')
|
|
|
|
|
|
|
+ if (this.state.notifyToken) {
|
|
|
|
|
+ Clipboard.setString(this.state.notifyToken);
|
|
|
|
|
+ toastShort('Copied')
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
return (
|
|
return (
|
|
|
<View style={styles.container}>
|
|
<View style={styles.container}>
|
|
|
- <Text style={styles.text}>注册的Token:{this.state.notifyToken}</Text>
|
|
|
|
|
|
|
+ <Text style={styles.text}>Device Token:{this.state.notifyToken || "none"}</Text>
|
|
|
|
|
+ <Text style={styles.text}>Server Token:{this.state.serverToken || "none"}</Text>
|
|
|
|
|
+ { utils.isNotEmpty(this.state.notifyToken) &&
|
|
|
|
|
+ <View style={styles.text}>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ text='Copy Token'
|
|
|
|
|
+ elevation={2}
|
|
|
|
|
+ onClick={() => this.copyToken()}
|
|
|
|
|
+ />
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
<View style={styles.text}>
|
|
<View style={styles.text}>
|
|
|
<Button
|
|
<Button
|
|
|
- text='复制Token'
|
|
|
|
|
- elevation={2}
|
|
|
|
|
- onClick={() => this.copyToken()}
|
|
|
|
|
- />
|
|
|
|
|
- </View>
|
|
|
|
|
- <View style={styles.text}>
|
|
|
|
|
- <Button
|
|
|
|
|
- text='发送本地通知'
|
|
|
|
|
|
|
+ text='Send Local Notification'
|
|
|
elevation={2}
|
|
elevation={2}
|
|
|
onClick={() => this.localNotification()}
|
|
onClick={() => this.localNotification()}
|
|
|
/>
|
|
/>
|
|
|
</View>
|
|
</View>
|
|
|
<View style={styles.text}>
|
|
<View style={styles.text}>
|
|
|
<Button
|
|
<Button
|
|
|
- text='发送远程通知'
|
|
|
|
|
|
|
+ text='Request Remote Notification'
|
|
|
elevation={2}
|
|
elevation={2}
|
|
|
onClick={() => this.remoteNotification()}
|
|
onClick={() => this.remoteNotification()}
|
|
|
/>
|
|
/>
|
|
|
</View>
|
|
</View>
|
|
|
|
|
+ { utils.isNotEmpty(this.state.notifyToken) &&
|
|
|
|
|
+ <View style={styles.text}>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ text='Update Firebase Token'
|
|
|
|
|
+ elevation={2}
|
|
|
|
|
+ onClick={() => this.updateToken()}
|
|
|
|
|
+ />
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
<View style={[ui.flex1, ui.flexcc]}>
|
|
<View style={[ui.flex1, ui.flexcc]}>
|
|
|
<Text style={styles.os}>{Platform.OS}</Text>
|
|
<Text style={styles.os}>{Platform.OS}</Text>
|
|
|
</View>
|
|
</View>
|