简体   繁体   English

如何检测用户当前使用的推送通知设备?

[英]How do I detect which push notification device a user currently using?

I would like to show a list of devices that a user has enabled push notifications for in their dashboard.我想显示用户在其仪表板中启用推送通知的设备列表。 In this list I would like to highlight the current device they are using if it's in the list or show a "Add this device" button if it's not in the list.在此列表中,我想突出显示他们正在使用的当前设备(如果它在列表中),或者如果它不在列表中,则显示“添加此设备”按钮。 So let's say the user has enabled push notifications on their phone and on their desktop.因此,假设用户在他们的手机和桌面上启用了推送通知。 They log into the dashboard on their phone.他们在手机上登录仪表板。 Is there a way for me to tell that it's their phone?有没有办法告诉我这是他们的电话? Also, what if they decide to block notifications in their browser or do a factory reset (my database won't sync obviously)?另外,如果他们决定在浏览器中阻止通知或进行出厂重置(我的数据库显然不会同步)怎么办? So what would be a good way to purge that old device from the list?那么从列表中清除旧设备的好方法是什么?

I'm doing this because I want a good user experience and I want to give users the option to toggle push notifications on/off per device through the dashboard without making them do it through the browser which could end up in them never re-enabling them again.我这样做是因为我想要一个良好的用户体验,并且我想让用户可以选择通过仪表板打开/关闭每个设备的推送通知,而不是让他们通过浏览器进行操作,这可能最终导致他们永远无法重新启用他们再次。

I was thinking maybe passing a hardcoded (but generated) id variable into the service worker?我在想也许将硬编码(但生成)的 id 变量传递给服务人员?

let deviceId = 0;

But this seems really clunky.但这似乎真的很笨拙。 Is there a better way?有没有更好的办法?

PS. PS。 My backend is PHP and MYSQL.我的后端是 PHP 和 MYSQL。 Don't think it matters, but any answers with server-side code I'd prefer with those.不要认为这很重要,但是我更喜欢服务器端代码的任何答案。 I think this is all client-side though.我认为这都是客户端。

If the user resets the browser (device), you will only discover it by trying to send something and getting a 404. So it's not possible to always be able to show a list of devices with 100 % correct info if you're not spamming the user all the time.如果用户重置浏览器(设备),您只能通过尝试发送某些内容并获得 404 来发现它。因此,如果您不发送垃圾邮件,则不可能始终显示具有 100% 正确信息的设备列表用户一直。 You could probably show something like the last time a push was delivered to a certain device, maybe that would be good UX-wise.您可能会显示上一次推送发送到某个设备时的内容,这可能是很好的用户体验。

To detect which of the devices is the current one looking at the list, simply use some sort of an id that is saved in the db when the push subscription is created.要检测哪些设备是当前查看列表的设备,只需使用创建推送订阅时保存在数据库中的某种 id。 Then hold on to that id in the device (browser) and based on that, make one of the items on the list pop up.然后在设备(浏览器)中保留该 ID,并在此基础上弹出列表中的一项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Servlets - 如何检测用户是否来自移动设备? - Java Servlets - How do I detect if a user is from a mobile device? 如果用户离线,我如何排队推送通知消息并在他们重新在线时推送? - How do i queue push notification message if user is offline and push when they are back online? 我该如何检测到 <View> 我的手指目前在吗? - How can I detect which <View> my finger is currently on? 如何在 HTML/JS 中找到用户使用的设备? - How do I find which device the user is on in HTML/JS? 如果用户当前在页面上处于活动状态,我如何使用 JavaScript/jQuery 进行检测? - How can I detect with JavaScript/jQuery if the user is currently active on the page? 如何检测浏览器选项卡当前是否可见并使用Javascript渲染? - How do I detect if a browser tab is currently visible and rendering using Javascript? 如何使用 javascript 为 PWA 应用程序检测设备级通知打开或关闭? - How to Detect the device level Notification ON or OFF using javascript for PWA Application? 如何检测用户使用的是 Excel 在线版还是 Excel 桌面版 - How do I detect if the user is using Excel online or Excel desktop 如何使用JavaScript检测用户的IP地址? - How do I detect a user's IP address using javascript? 如何使用 VueJS、NUXT 和 NODEjs 在客户端计算机上获取当前登录到操作系统的用户 - How do I fetch the user currently logged into the OS on the client computer, using VueJS, NUXT and NODEjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM