Table of contents



Official Content

This document is a brief guide on how to use Local Notifications in GeneXus Native Mobile apps.

Step 1: Checking the objects that will let you add Local Notifications

There are two objects in the GeneXus Core module that are used to enable Local Notifications.

image_202353193827_1_png
Read about them in the LocalNotifications external object article.

The LocalNotifications external object includes a method called CreateAlerts that expects a variable based on the LocalNotificationsInfo SDT as an input parameter.

When this action is executed, the app will schedule all the local notifications passed in the LocalNotifications SDT variable.


Step 2: Programming the Local Notifications

To make them work, just create the following Procedure object (e.g.: named "SendLocalNotificationsServer").

In this example, this Procedure is created to load the LocalNotificationsInfo SDT. Bear in mind that this can be done differently, as it is not compulsory to do it with a Procedure.

Parm:

parm(out: &MySdtLocalNotifications);

Source:

&MySdtLocalNotificationsItems.DateTime = ymdhmstot(2012,06,07,16,56,00) 
&MySdtLocalNotificationsItems.Text = "My Local Test"
&MySdtLocalNotifications.Add(&MySdtLocalNotificationsItems)

Variables:

MySdtLocalNotifications -> SDTLocalNotifications
MySdtLocalNotificationsItems -> SDTLocalNotifications.Item

Next, create a Panel object:

Layout:

LocalNotifIphone3

Events:

 Event 'SendNotification'
      Composite
          &MySdtLocalNotifications = SendLocalNotificationsServer()
          LocalNotifications.CreateAlerts(&MySdtLocalNotifications)
      EndComposite
 EndEvent

Step 3: Execution

Run your application.

First, press the Panel button to start scheduling Local Notifications.

After that, the Notifications will be scheduled and they will appear on your device at the time specified.

When the local notification is added:

LocalNotifIphone1

When the local notification is triggered:

LocalNotifIphone2

Sample

A working example of this method can be downloaded from: WorkingWithLocalNotifications.

Troubleshooting

The Create method of the external object returns a numeric value. If the returned value 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.

Availability

This feature has been added to GeneXus in:

  • Apple since GeneXus Evolution 2 Upgrade 1
  • Android since GeneXus Evolution 2 Upgrade 3

Notes

  • Since iOS 8, local notifications require authorization from the user. The user will be automatically asked for this authorization the first time you use this API. If you want to do it manually, it can be done by using the Permissions external object for Apple applications (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.

Scope

Generators:  Apple Android

See Also

LocalNotifications external object

  

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant