Worklight: Push notification without User ID

后端 未结 3 2112
轮回少年
轮回少年 2020-12-06 21:12

Kindly suggest, is it possible to send push notification without having user ID ? Lets say we want to send push messages to all users who have downloaded our App. OR due to

相关标签:
3条回答
  • 2020-12-06 21:44

    You need a list of subscriptions to send push notification in Worklight and the adapter (server) side API to get all the subscriptions is

    WL.Server.getUserNotificationSubscription(eventSource, userId);

    So without userId, it is not possible to send push notifications.

    I am not sure about security concerns since userID is nothing but username used to login to the app. If both your app and event source have securityTests, then storing subscriptions along with userId is automatically taken care by Worklight.

    0 讨论(0)
  • 2020-12-06 22:02

    Starting in Worklight 6.2, you can send notification to all users (subscribed or not) using the 'broadcast notification' feature.

    For more info, refer to http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.dev.doc/devref/c_push_notif_broadcast.html

    To send the broadcast notification, you can use WL.Server.sendMessage( applicationId, notificationOptions ). More info can be found at http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.dev.doc/devref/c_send_push_notifications.html

    0 讨论(0)
  • 2020-12-06 22:09

    One way or another, you need a way to identify the user. It will come down to what you consider to be a 'userID'. There is a way to distinguish between users without using a permanent userID. You can use the persistent cookie realm. If you add this to your authenticationConfig.xml file:

           <realm name="PersistentCookie" loginModule="WeakDummy">
                <className>com.worklight.core.auth.ext.PersistentCookieAuthenticator</className>
            </realm>
    

    Then a unique ID based on a persistent cookie will be created for the user when they connect to the worklight server:

    "PersistentCookie":{"userId":"6410a0f9-98fb-4940-a127-da940c5d7e16","attributes":{},"isUserAuthenticated":1,"displayName":"6410a0f9-98fb-4940-a127-da940c5d7e16"}
    

    No further interaction is required by the user or the developer. Simply adding the class to authenticationConfig.xml is enough to generate the userID.

    You can use this cookie to subscribe a user for push notifications. If for security reasons you wish to no longer have this user identified by this persistentCookieID, then you can simply clear the cookies on the application and a new ID will be generated for the user. They will then need to resubscribe for push notifications if a new persistentCookieID is generated.

    0 讨论(0)
提交回复
热议问题