Rya*_*ent 7 android react-native expo
我正在与Expo一起开发本机消息应用程序。每当用户收到新消息时,我都会从服务器发送通知。
如果应用程序当前处于打开状态,有什么方法不显示通知?
现在,我会在收到通知后立即使用它:
Notifications.dismissNotificationAsync(notification.notificationId);
Run Code Online (Sandbox Code Playgroud)
但是有0.5秒的延迟,通知有时间出现在托盘中并在被取消之前触发声音。我完全不想显示它。
小智 9
当应用程序运行时收到通知时,setNotificationHandler您可以设置一个回调来决定是否应向用户显示通知。
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
Run Code Online (Sandbox Code Playgroud)
当收到通知时,handleNotification以传入通知作为参数来调用。该函数应在 3 秒内响应行为对象,否则通知将被丢弃。如果通知处理成功,handleSuccess则使用通知的标识符进行调用,否则(或超时)handleError将被调用。
当处理程序未设置或未及时响应时,默认行为是不显示通知。
如果您不使用 setNotificaitonHandler,则当应用程序位于前台时,将不会显示新通知。
setNotificationHandler因此,您只需设置为null应用程序初始化时即可。
Notifications.setNotificationHandler(null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
649 次 |
| 最近记录: |