如何让通知振动 phone react native expo
How to make notifications vibrate phone react native expo
我需要通知让 phone 重复振动,直到用户执行点击通知等操作。我还没有找到方法来完成这项工作。起初,我试图使用 Vibrate Api from react native expo. But I later came to realize that the expo cannot react to notifications if app is killed and user did not interact with the notification as stated here. The only other way is to give the notification a setting to vibrate and the interval. But I can't seem to find a way to do that. I am using node js to send the notification, which is practically the same code as this. This are the only formats used to send a message. There is no vibrate. But on the initial page 来解决它,我看到他们添加了振动。我一定是在某个地方弄错了或者迷路了。我想这可以以某种方式完成,否则就不会有警报应用程序。我怎样才能做到这一点?在我的 android phone 上,通知甚至根本不振动,如果我没有此功能,该应用程序将毫无用处。谢谢 ):
后来我找到了这个问题的答案。在 andriod 上,您必须创建一个 channel 并在发送通知时包含它。文档中的所有解释。您将能够创建振动模式等。另外,如果您像我一样在后端发送通知(我使用的是 nodejs),您仍然可以创建一个频道,但它必须在前端。在 useEffect 中使用此代码:
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
您可以将 'default' 替换为您想要调用通知渠道的任何名称。我还没有在 ios 上找到如何做到这一点。如果我这样做,我会更新。希望我不会忘记 ):
我需要通知让 phone 重复振动,直到用户执行点击通知等操作。我还没有找到方法来完成这项工作。起初,我试图使用 Vibrate Api from react native expo. But I later came to realize that the expo cannot react to notifications if app is killed and user did not interact with the notification as stated here. The only other way is to give the notification a setting to vibrate and the interval. But I can't seem to find a way to do that. I am using node js to send the notification, which is practically the same code as this. This are the only formats used to send a message. There is no vibrate. But on the initial page 来解决它,我看到他们添加了振动。我一定是在某个地方弄错了或者迷路了。我想这可以以某种方式完成,否则就不会有警报应用程序。我怎样才能做到这一点?在我的 android phone 上,通知甚至根本不振动,如果我没有此功能,该应用程序将毫无用处。谢谢 ):
后来我找到了这个问题的答案。在 andriod 上,您必须创建一个 channel 并在发送通知时包含它。文档中的所有解释。您将能够创建振动模式等。另外,如果您像我一样在后端发送通知(我使用的是 nodejs),您仍然可以创建一个频道,但它必须在前端。在 useEffect 中使用此代码:
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
您可以将 'default' 替换为您想要调用通知渠道的任何名称。我还没有在 ios 上找到如何做到这一点。如果我这样做,我会更新。希望我不会忘记 ):