HowTo: Using Devices Registration Service for Push Notifications

Official Content
This documentation is valid for:

Every time an end-user executes a GeneXus application in a Smart Device which has Enable Notifications property enabled, the service configured in the Registration Handler property is automatically executed in order to register and store the device information to be used in the future to send messages to the device.

A Procedure object called NotificationsRegistrationHandler is included as a sample of this service under GeneXus/SD/Notifications directory with a typical implementation.

Rules:
   parm(in:&DeviceType, in:&DeviceId, in:&DeviceToken, in:&DeviceName);

Code: 
   for each
      where DeviceType = &DeviceType
      where DeviceId  = &DeviceId   
      DeviceToken = &DeviceToken    
      DeviceName = &DeviceName      
   when none
      new
         DeviceType  = &DeviceType
         DeviceId = &DeviceId
         DeviceToken = &DeviceToken
         DeviceName = &DeviceName
      endnew
   endfor

The Parm rule must have these four parameters in order to retrieve the device information.

  • &DeviceType : SmartDeviceType
  • &DeviceId : Character(128)
  • &DeviceToken : Character(1000)
  • &DeviceName :Character(128).

After the execution of the service, information like the following is registered:

  • DeviceType :
       iOS or Android
  • DeviceId :
       8bb3ud27c7cce885b1c41a3cf5f5bd3m4b22w96d
  • DeviceToken :
    When the Notifications Provider property has a value different from "None", this token contains information about the device in a JSON format.
    An example of these data (using OneSignal as Notification Provider) look as follows:
       {
           "DeviceToken": "PJy0nafLvZiXvbGlmYuidCpA7JY5ryuW30KoQmpOs=",
           "DeviceId": "8bb3ud27c7cce885b1c41a3cf5f5bd3m4b22w96d",
           "DeviceType": 1,
           "NotificationPlatform": "OneSignal", 
           "NotificationPlatformId": fb508412-2f91-46b1-90e1-f052247d1f8c
       }

*If the DBMS is MySql, DeviceToken must be defined as VarChar(1000), not Char(1000), otherwise it won't record the entire Token

If no Notification Provider is used, the token should look as follows:
    PJy0nafLvZiXvbGlmYuidCpA7JY5ryuW30KoQmpOs=

  • DeviceName :
       iPhone Mary

With this information, you can start sending messages to registered devices (those that use your application).

Note 

  • If you have a completely offline application and you need this Registration Handler procedure to be generated offline exclusively, set Main property = False and Connectivity Support property = Offline
  • Device registration does not work if the developer is prototyping with KBN (Knowledge Base Navigator) or simulators.
  • The Registration Handler service is called when the application is opened.

See also

HowTo: Configuring Push Notifications in iOS Applications
HowTo: Configuring Push Notifications in Android Applications

Troubleshooting

  • Android devices are not being registered
    • Android Sender Id and/or Android Sender API Key properties from the main object are not set.
    • Simulators without Google Play Services don't support Firebase, so they are not being registered. Use devices instead.




Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.