ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Mobile specific functions / Phone functions
  • Overview
  • Principle
  • Push notifications in the mobile application
  • Managing push notifications in the application server
  • Available examples
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
A mobile device can receive push notifications. A notification is a message that is displayed (and stored) on the device, in the notification center. A notification can be used to start a process for example.
A notification is sent from a remote application, usually found on a server.
The application for sending notifications can be developed in WINDEV or WEBDEV, or via external tools.
Push notifications can be sent:
  • to one or more known, specific devices.
  • Android to any set of devices that are subscribed to a specific topic (this is known as "topic messaging"). For example, a sports app could allow users to subscribe to notifications on all the results of a specific team.
Principle
Four elements are required to create a push notification system:
  • A mobile application (iOS or Android) run on the appropriate device.
  • A notification service that is used to distribute the push messages to the phones or tablets. This service is supplied:
    • by Google: Firebase
      Remark: the application created before version 22 are using the Google Cloud Messaging mechanism (GCM). This mechanism will be made obsolete by Google from April 2019.
    • by Apple (APM).
  • An application server (or provider) that decides to send the messages and that establishes the communication with the business database (this server can be a web service or a WEBDEV or WINDEV application).
  • A database, used to store the identifiers of the different devices receiving the push messages as well as business data.
The global operating mode of push messages is as follows:
Notification scheme
  1. The application registers toward the Apple or Google service by using the "device id" and the "application id".
  2. If the registration is successful, the Apple or Google service returns a token (or "registration id") to the application.
  3. The application transmits the token to the application server (provider).
  4. The server stores the token in its database.
A push message is send according to the following method:
a. The application server sends a message (by using an SSL socket (iOS) or an HTTPS socket (Android)) containing the token to the Apple or Google service.
Remark: this sending can be done by an external application, as long as this one can access the business database and the certificate used for the communication with the notification service.
b. The Apple or Google service transmits the message to the relevant device.
Android Android notifications on a given topic (subscription):
With this type of notification, it is not necessary to store the identifiers of the devices.
In this case, a push message is sent as follows:
  1. Android applications subscribe to a topic.
  2. The application server sends a push message on a topic.
  3. Google's service performs fanout, i.e., sends the message to the devices subscribed to that topic.
Push notifications in the mobile application
You can use several functions to manage push notifications in a mobile application:
NotifPushDisableDisables the management of push notifications for a WINDEV Mobile application (Android or IOS).
NotifPushEnableEnables the management of push notifications in a WINDEV Mobile application (Android or iOS).
NotifPushProcedureSpecifies the WLanguage procedure called when a push notification is received by a WINDEV Mobile application (Android or iOS).
NotifPushSubscribeSubscribes the current Android application to a topic.
NotifPushUnsubscribeUnsubscribes an application from a topic.
Caution: a specific configuration is required in order for the mobile applications to operate:
The behavior when a notification is received is as follows:
  1. If the application is closed, the system displays the notification in the notification bar. The user can choose to validate the notification. If he does, the application is started.
    Android If no message is specified in the notification, the application is started and the notification is not displayed. Starting with Android 10, it is no longer possible to open a window when the application is in the background. This behavior is no longer supported.
    Two cases may occur once the application is started:
    • If NotifPushProcedure was called in the project initialization code, the global procedure passed to this function as parameter is called and the first window of the application is not opened.
      Remark: OpenMobileWindow must be called in the procedure.
    • If NotifPushProcedure was not called, the first application window is opened.
  2. If the application is already started:
    • Android If a message or a title is specified in the notification, the system displays the notification in the notification bar. If the user clicks the notification, the procedure specified in NotifPushProcedure is called (nothing happens if it is not specified).
      If no message and no title is specified in the notification, the notification is not displayed and the procedure is called directly.
    • iPhone/iPad Two cases may occur:
      • If the application is in the foreground, the procedure of NotifPushProcedure is called directly. If no procedure is specified, only an "ok" button is displayed.
      • If the application is in the background, the system displays the notification. If the user validates the notification, the application returns to the foreground and the procedure of NotifPushProcedure is called.
Remarks:
  • The exeLaunch constant of ExeInfo allows you to know if the application was automatically started by the system further to the reception of a push notification:
    ExeInfo(exeLaunch) = exePushNotification
  • WinStatus allows you to check (if necessary) the existence of a window in order to open it:
    // Summary: Procedure called when clicking on a PUSH notification
    PROCEDURE onPush(MyNotif is Notification)

    IF WinStatus("WIN_Main") = NotFound THEN
    // WIN_Main is already open or displayed
    ReceivePushNotif(MyNotif, True)
    ELSE
    // Open home window
    OpenMobileWindow(WIN_Main, MyNotif)
    END
Managing push notifications in the application server
The application server is the WINDEV application or the WEBDEV website that sends the push notifications.
This application server sends push notifications:
  • via NotifPushSend. Notifications are then sent to devices identified by their token.
    Caution: NotifPushSend must know the identifiers (tokens) of the devices that should receive the notification. This information must be returned by the mobile application.
  • Android via NotifPushSendSubscriber. Notifications are sent to all the devices that are subscribed to a particular topic.
Available examples
WINDEV Mobile is provided with the following examples:
  • WD_Push_Server (Web service):
    1. In the project code, it is necessary to specify:
      • The Android API key
      • The type of Android platform: use the npeFirebase or npeGCM constants (npeFirebase by default).
      • The path of the certificate that will send the iOS notifications (Certificate to be deployed with the web service).
    2. Deploy the web service.
    3. Retrieve the URL of the deployed WSDL.
  • WM Push (Mobile application that receives notifications):
    1. Replace the URL of the web service already imported into the project with the previously retrieved URL.
    2. Android deployment:
      • Retrieve the google-services.json Firebase configuration file, otherwise retrieve the project number in Google Cloud Messaging.
      • In the Android generation wizard, make sure that the name of the package is the same as the one defined in the Google services.
    3. iOS deployment: Specify the same bundle as the one defined in the Apple console
  • Send Push (Client application to send notifications via the web service):
    1. Replace the URL of the web service already imported into the project with the previously retrieved URL.
    2. Run the application to send notifications.
    3. For iOS, do not forget to specify the bundle of the application to which the notifications are to be sent.
Related Examples:
WM Push Cross-platform examples: WM Push
[ + ] This example shows how to receive Push notifications.
It calls the PushNotifActive function and returns the identifier to "WD Push Server", which stores it.
Then, the "Send Push" example reads this identifier and sends Push notifications to this example.
WD_Push_Server Cross-platform examples: WD_Push_Server
[ + ] This example is a webservice used to store the identifiers required to sent Push notifications to mobile devices.
The "WM Push" application stores the Push identifiers in the database of this example.
The "WD Send Push" example then reads these identifiers in order to send the notifications.
Send Push Cross-platform examples: Send Push
[ + ] This example allows you to send push notifications to Android and iOS devices.
It retrieves the identifiers of the mobile devices in the HFSQL database of the "WD Push Server" example, then sends the notifications via the NotifPushSend function.
Minimum version required
  • Version 19
Comments
Click [Add] to post a comment

Last update: 03/07/2024

Send a report | Local help