且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Worklight:如何获取Push订阅的当前设备ID

更新时间:2023-01-27 17:26:35


  1. 在适配器中注册事件源时,您可以指定onUserSubscribe回调。一旦用户订阅推送通知,就会调用此回调。调用后,此回调将接收用户订阅对象作为参数。该对象包含userId和deviceId。

  1. When registering event source in adapter you can specify onUserSubscribe callback. This callback will be invoked once user subscribes to push notifications. Once invoked this callback will receive user subscription object as a parameter. This object contains both userId and deviceId.

WL.Server.getUserNotificationSubscription(event-source,userId)将返回带有设备订阅数组的用户订阅对象。每个设备订阅对象都有deviceId。

WL.Server.getUserNotificationSubscription("event-source","userId") will return user subscription object with an array of device subscriptions. Each device subscription object will have deviceId.

在客户端,deviceId是设备认证领域的userId。例如。如果您不使用配置,您可以使用WL.Client.getUserInfo(wl_deviceNoProvisioningRealm,userId)获取deviceId;

On a client side deviceId is a userId of device authentication realm. E.g. in case you use no provisioning you can get deviceId by using WL.Client.getUserInfo("wl_deviceNoProvisioningRealm", "userId");

服务器端没有知道你的当前设备。您可以使用onUserSubscribe回调将特定设备标记为最新。

Server side doesn't know your "current" device. You can use onUserSubscribe callback to mark specific device as latest.

用户订阅对象可以拥有自定义属性,您可以使用它们来维护订阅状态。

user subscription object can have custom properties, you can use them to maintain subscription state.