Local Notifications

756
0
08-29-2022 10:45 AM
TrevorFrame
Esri Contributor
1 0 756

Local notifications are a great tool for notifying users of important information in a timely manner. What’s great is they are simple to set up and use within your AppStudio apps. In this post, we will explain how in a few simple steps, you can set up local notifications in your app, schedule the notification to be sent to your user’s device, and some examples of where local notifications can be used. 

 

How to setup Local Notifications  

AppStudio has an AppFramework component for easily scheduling local notifications to any device type. To use it, first import the library using the statement below.  

 

 

import ArcGIS.AppFramework.Notifications.Local 1.0 

 

 

Once imported, a LocalNotification component can be created within the scope of where it needs to be called. It’s easiest to setup in the root component so it can be used anywhere inside the application. Below is an example code. 

 

 

LocalNotification { 
     id: localNotification  
} 

 

 

How to schedule Local Notifications 

Once the component has been created a function can be called to schedule and deliver the local notification. There are two instances of the schedule method that can be used. One method will be an immediate trigger of the notification, one will be a delayed trigger of the notification. To use them call the schedule method and pass the following parameters: 

  1. string title 
  2. string message 
  3. int timeInMilliSeconds (optional)  

Below is an example schedule call for the local notification created above using the id localNotification.  

 

 

localNotification.schedule(“Title”, “This will be the notification message.”, 10000) 

 

 

The above example would display a notification that looks like the below image after 10 seconds.  

IMG_4345.jpeg

 

Extra note 

There is one drawback to using local notifications. To schedule them, the application must be running. Luckily, the application can be running in the foreground or background.   

 

Example Use Case 

Local notifications can be useful when combining them with other features or functionalities. An example of this is creating an app that utilizes geofences or geotriggers. To learn more about these, you can read about the geotrigger sample here. How the application works is it can consume a web map and creates geofences from the features in the map. Some geotrigger monitors are created to track the device location and features within a feature table and will trigger if their locations overlap. When the trigger event occurs, a local notification can be scheduled to display a message to the user. This can be an instant notification to alert the user or a delayed notification to act as a reminder. Some other features that work well with this are: device vibration, in app notifications page to view notification history, and text to speech messages.   

Conclusion 

Now you know how easy it is to setup and consume local notifications in your AppStudio apps. They are great for alerting users of useful information either immediately or as a future reminder, and they work while the application is running in the foreground or background. 

About the Author
Product Engineer working with AppStudio to build cross platform mobile applications.