userID in getUserNotificationSubscription WORKLIGHT Pushnotification

≯℡__Kan透↙ 提交于 2019-12-13 04:40:03

问题


I am implementing push notification in my IBM worklight project. Sample code in developerworks do it with some authentication challenger mechanism to do the subscription. I somehow used the same Authentication challenge to do the subscription (although my app design doesn't need to do this). In the sample code actual trigger of notification call is not written.

I found out from web resource that WL.Server.getUserNotificationSubscription(eventSourceName, userId) need to be used to get the subscribed user details. However I don't know how to get userId details here? Please let me know what is userId here and how to get its value.


回答1:


Here is information regarding WL.Server.getUserNotificationSubscripion:

getUserNotificationSubscription:

getUserNotificationSubscription(eventSource, userId) Returns a subscription object for a user. Returns a subscription object for the user with the specified ID to the specified event source.

Parameters: eventSource - Mandatory. A string containing the name of the event source. userId - Mandatory. A string containing the user ID, created during the login process. The user ID can be obtained by calling WL.Server.getActiveUser.

Returns: The method returns a subscription object that contains the user ID and the mutable subscription state. Example: {userId: 'bjones', state: {numCoupons: 3}}

Note: All subscription object fields are read-only, except for the user subscription state. You can modify the user subscription state in your JavaScript code, and then must use the save method to save it to the IBM® Worklight® database.

As you can see the userId is the specific user that was created during the login and authentication process. Worklight provides a server side API WL.Server.getActiveUser() which allows you to retrieve the current user.

In regards to your other statement saying "in the sample code actual trigger of notification call is not written. " Worklight actually provides a jar file inside of the sample project that allows you to trigger the notification. Here is some more information for this backend emulation:

Let me know if you have any further questions.



来源:https://stackoverflow.com/questions/22497671/userid-in-getusernotificationsubscription-worklight-pushnotification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!