如何制作通知振动电话反应本地博览会

发布于 2025-01-26 16:35:48 字数 814 浏览 3 评论 0原文

我需要通知以重复振动手机,直到用户执行诸如单击通知之类的动作。我发现还没有办法完成这项工作。首先,我试图使用振动型API 来自React Native Expo。但是我后来意识到,如果杀死应用程序,并且用户没有与通知 。唯一的方法是将通知设置为振动和间隔。但是我似乎找不到这样做的方法。我正在使用节点js发送通知,该通知实际上与此。这是唯一的格式用于发送消息的格式。没有振动。但在

I need notifications to vibrate the phone repeatedly until the user performs an action like clicking on the notification. I have found no way to make this work yet. At first, I sought to solve it using the 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, I see them adding vibrate. I must be mistaken somewhere or lost. I suppose this can be done somehow, else there wouldn't be alarm apps. How can I do this? On my android phone, the notification doesn't even vibrate at all and The app would be useless if I do not have this feature. Thank you ):

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2025-02-02 16:35:48

后来我找到了答案。在Andriod上,您必须创建一个 Channel> Channel ,并在发送通知时包含它。文档中的所有解释。您将能够创建一个振动模式,依此类推。另外,如果您像我一样在后端发送通知(我使用nodejs),那么您仍然可以创建一个频道,但必须在前端。在使用效果中使用此代码:

if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
  name: 'default',
  importance: Notifications.AndroidImportance.MAX,
  vibrationPattern: [0, 250, 250, 250],
  lightColor: '#FF231F7C',
});

}

您可以用要调用通知频道的任何名称替换“默认”。我还没有在iOS上找到如何做到这一点。如果这样做,我将更新。希望我不会忘记):

I later found the answer to this. On andriod, you must create a channel and include it when sending the notifications. All explanation in the docs. You would be able to create a vibration pattern and so forth. Also if your like me who did the sending of notification in the backend (I used nodejs), you can still create a channel but it has to be on the frontend. Use this code in a useEffect:

if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
  name: 'default',
  importance: Notifications.AndroidImportance.MAX,
  vibrationPattern: [0, 250, 250, 250],
  lightColor: '#FF231F7C',
});

}

You can replace 'default' with whatever name you want to call the notification channel. I haven't yet found out how to do this on ios. If I do, I will update. Hopefully I don't forget ):

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文