The LocalNotifications external object enable your app to alert users of scheduled events or alarms in the background, with no servers required as in Push Notifications in Smart Devices Application.
This document is a brief guide of how to use Local Notifications in GeneXus for Smart Devices.
There are two objects that are going to be used to enable Local Notifications on the GeneXus Core module.
LocalNotifications structured data types
This Structured Data Type (SDT) is used to define the configuration of the Local Notification. It is a collection of Items with DateTime and Text. The DateTime will be used to know when that Local Notification will be triggered, and the text will be the info shown to the user. You can define as many Local Notifications as you want. A single item on the SDT LocalNotifications Item is equivalent to one Local Notification.
LocalNotifications external object
This external object has a method called CreateAlerts which expects as an input parameter an instance of a variable based on SDT LocalNotifications. When this action is executed, the app will schedule all the local notifications passed on the SDT LocalNotifications.
To make them work just to create the following Procedure (e.g: named "SendLocalNotificationsServer").
In this example, we are creating this procedure to load the SDTLocal Notifications, but this can be done differently because it is not compulsory to do it with a procedure.
&MySdtLocalNotificationsItems.DateTime = ymdhmstot(2012,06,07,16,56,00)
&MySdtLocalNotificationsItems.Text = "My Local Test"
MySdtLocalNotifications -> SDTLocalNotifications
MySdtLocalNotificationsItems -> SDTLocalNotifications.Item
Next, let's create a Panel for Smart Devices object:
&MySdtLocalNotifications = SendLocalNotificationsServer()
Run your application.
First, hit the Panel for Smart Device button to start scheduling Local Notifications. After that, the Notifications have been scheduled and they will appear on your device at the time specified.
When the local notification is added:
When the local notification is fired.
A working example of this method can be downloaded from: WorkingWithLocalNotifications.
The Create method of the external object returns a numeric value. If the value returned is 0, it means that there was no error in the execution. Otherwise, if the numeric value is different than 0, an execution error occurred.
This feature has been added to GeneXus in:
- iOS as of GeneXus Evolution 2 Upgrade 1
- Android as of GeneXus Evolution 2 Upgrade 3
- Since iOS 8, the local notifications require an authorization from the user. The user will be automatically asked for this authorization the first time you use this API. In case that the developer wants to do it manually, it can be done by using Permissions external object (e.g. when the app is in the background).
- If the DateTime field of the LocalNotification SDT is empty, the notification will be triggered instantly.
||Smart Devices (iOS, Android)