........
使用套件
@react-native-community/push-notification-ios
react-native-push-notification
react-native-background-fetch
<Modal
popup
style={styles.popupView}
title="visible_WEB_popup"
visible={this.state.visible_time_popup}
animationType="slide-up"
onClose={() => { this.setState({ visible_WEB_popup: false, }); }}
footer={[{ text: 'Ok', onPress: () => { console.log('ok'); this.setState({ visible_WEB_popup: false, }); } }]}
maskClosable={true}>
<View style={styles.modalOpet}>
<TouchableOpacity
style={{ flexDirection: "column", borderTopLeftRadius: 20, backgroundColor: "#fa507b", flex: 1 }}
onPress={async () => {
this.setState({
visible_time_popup: false,
});
}}>
<Text style={styles.modalTXT}>close modal</Text>
</TouchableOpacity>
<TouchableOpacity
style={{ flexDirection: "column", backgroundColor: "#122244", flex: 1 }}
onPress={async () => {
this.setState({
visible_time_popup: false,
});
}}>
<Text style={styles.modalTXT}>立即發布</Text>
</TouchableOpacity>
<TouchableOpacity
style={{ flexDirection: "column", borderTopRightRadius: 20, backgroundColor: "#50d3fa", flex: 1 }}
onPress={async () => {
await this.push_FCM_time();
this.setState({
visible_time_popup: false,
});
}}
>
<Text style={styles.modalTXT}>set time & close modal</Text>
</TouchableOpacity>
</View>
<View style={{ paddingVertical: 20, paddingHorizontal: 20 }}>
<Text style={{ margin: 16 }}>use24Hours</Text>
<DatePickerView
value={this.state.value24hours}
onChange={v => {
this.setState({ value24hours: v })
console.warn(this.state.value24hours)
}}
/>
</View>
</Modal>
PushNotification.configure({
onRegister: function (token) {
console.log('TOKEN:', token);
if (token.os == "ios") {
console.log('TOKEN:', token.os);
} else if (token.os == "android") {
console.log('TOKEN:', token.os);
}
}.bind(this),
onNotification: function (notification) {
console.log('NOTIFICATION:', notification);
console.log('NOTIFICATION DATA:', notification.data);
if (notification.data != null) {
console.log('NOTIFICATION DATA:', notification.data);
}
},
onAction: function (notification) {
console.log("ACTION:", notification.action);
console.log("NOTIFICATION inAction:", notification);
}, onRegistrationError: function (err) {
console.error(err.message, err);
},
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
});
PushNotification.localNotificationSchedule({
message: "My button Notification Message" + new Date(this.state.time),
date: new Date(this.state.APN_time),
allowWhileIdle: false,
});