☆我的源代码信息☆
let token = await Notifications.getExpoPushTokenAsync();
console.log(token);
List<String> somePushTokens = Arrays.asList("ExponentPushToken[yyyyyyyyyyyyyyyyyyyyyy])"; // example
☆我的问题☆
如果应用程序在前台打开,我不想显示推送。 因此,我阅读了世博会官方文件的第3项。 https://docs.expo.io/versions/latest/guides/push-notifications/
3. Handle receiving and/or selecting the notification
Determining origin of the notification
根据官方文档,如果“来源已打开”且“应用已打开”,则“原始”值将被“接收”。
如果“接收到”原始值,则我不想显示警报。 我可以根据来源值控制警报消息的接收吗?
我使用了此源代码。 当前,警报将无条件发送到电话。 它会无条件显示在手机上。
我希望控制在看着屏幕时不显示警报。
import React from 'react';
import {
Notifications,
} from 'expo';
import {
Text,
View,
} from 'react-native';
// This refers to the function defined earlier in this guide
import registerForPushNotificationsAsync from './registerForPushNotificationsAsync';
export default class AppContainer extends React.Component {
state = {
notification: {},
};
componentDidMount() {
registerForPushNotificationsAsync();
// Handle notifications that are received or selected while the app
// is open. If the app was closed and then opened by tapping the
// notification (rather than just tapping the app icon to open it),
// this function will fire on the next tick after the app starts
// with the notification data.
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}
_handleNotification = (notification) => {
this.setState({notification: notification});
};
render() {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>Origin: {this.state.notification.origin}</Text>
<Text>Data: {JSON.stringify(this.state.notification.data)}</Text>
</View>
);
}
}
所以我用了Notifications.dismissAllNotificationsAsync(); 但是,如果我将其放在源代码中,则在启动应用程序时,警报只会消失一次。
我根本无法停止闹钟。
componentDidMount() {
Notifications.dismissAllNotificationsAsync();
}