Skip to content
DiasFranciscoA edited this page Sep 22, 2022 · 35 revisions

LocalPushNotification_Cancel

This function will cancel a previously registered notification (using the function LocalPushNotification_Create), so the notification will not trigger its callback anymore.

Syntax:

LocalPushNotification_Cancel(uid);
Argument Type Description
uid string The notification’s unique identification string

 

Returns:

N/A

 

Example:

var _data = { name: "John", age: 12 };
    LocalPushNotification_Create("1 hour", 3600, "Hello", json_stringify(_data));
    
    // Later in the code
    
    LocalPushNotification_Create("1 hour");
  

This will create a notification similar to the code sample of the LocalPushNotification_Create function and afterwards will cancel the notifications. Meaning the notification will no longer trigger its callback event.

 

 

LocalPushNotification_Create

This function creates a new push notification that will trigger after a given amount of time as passed with a given unique identifier. This unique identification string can be whatever the developer wants and is used to access the notification afterwards (for cancelling it, LocalPushNotification_Cancel).

This function doesn't return any value but triggers an Async Push Notification Event callback when the task is completed.

NOTE Notifications work at an OS level meaning they will still fire if your application is in the background or closed.

Syntax:

LocalPushNotification_Create(uid, seconds, title, message, data);
Argument Type Description
uid string The notification’s unique identification string
seconds real The number of seconds the notification should be delayed by
title string The title shown in the OS notification
message string The body text shown in the OS notification
data string The data string to be attached to the notification. Note that this string can
be anything including an array/struct as long as it is in string format

 

Returns:

N/A

 

Triggers:

Asynchronous Push Notification Event
async_load Contents
Key Type Description
type string The string value "Local"
id string The notification’s unique identification string
title string The notification’s title shown in the OS
message string The notification’s body shown in the OS
data real The data string passed into the notification creation function

 

Example:

var _data = { name: "John", age: 12 };
    LocalPushNotification_Create("5 seconds", 5, "Hello", json_stringify(_data));

This will create a notification with a delay of five seconds and will add some data to it (the data is a struct converted to string format using json_stringify). This notification will then be handled in the Async Push Notification Event , as shown below.

var _type = async_load[? "type");
    if (_type == "Local")
    {
        var _title = async_load[? "title"];
        var _message = async_load[? "message"];
    
        var _dataJson = async_load[? "data"];
        var _data = json_parse(_dataJson);
        show_debug_message(_data);
    }
  

In the example we are simply reading the information back from the notification converting the data into to a struct using the json_parse method and then printig it as a debug message to the terminal.

 

 

 

LocalPushNotification_iOS_Permission_Request

This function requests permission to show notifications to the user; this is required under iOS.

This function doesn't return any value but triggers an Async Push Notification Event callback when the task is completed.

IMPORTANT If no permission is given no notifications will be received.

Syntax:

LocalPushNotification_iOS_Permission_Request();

 

Returns:

N/A

 

Triggers:

Asynchronous Push Notification Event
async_load Contents
Key Type Description
type string The string value "LocalPushNotification_iOS_Permission_Request"
success real Whether or not the task succeeded
value real Whether or not the permission has been granted

 

Example:

LocalPushNotification_iOS_Permission_Request();

This will request the user for local push notification permission. This callback will then be handled in the Async Push Notification Event , as shown below.

var _type = async_load[? "type");
    if (_type == "LocalPushNotification_iOS_Permission_Request")
    {
        if (!async_load[?"success"])
        {
            // There was a problem while requesting for permission.
            show_debug_message("Something went wrong");
            return;
        }
            
    
        if(async_load[?"value"])
        {
            // At this point we know we have been authorized to deliver notifications to the user.
            global.have_permission = true;
        }
        else
        {
            // At this point we know we have been denided to deliver notifications to the user.
            global.have_permission = false;
        }
    }
  

In the example above we check if the request was successful providing a debug message if not and we check if the permissionwas given or denied. 

 

 

LocalPushNotification_iOS_Permission_Status

This function requests for the permission status. Note that it will not request the user for notification permission, instead it just queries the OS for the current permission status.

This function doesn't return any value but triggers an Async Push Notification Event callback when the task is completed.

NOTE For requesting permission use LocalPushNotification_iOS_Permission_Request.

Syntax:

LocalPushNotification_iOS_Permission_Status();

 

Returns:

N/A

 

Triggers:

Asynchronous Push Notification Event
async_load Contents
Key Type Description
type string The string value "LocalPushNotification_iOS_Permission_Status"
success bool Whether or not the task succeeded
value PermissionStatus The current notification permission status

 

Example:

LocalPushNotification_iOS_Permission_Status();

This will query the OS for the current permission status. This callback will then be handled in the Async Push Notification Event , as shown below.

var _type = async_load[? "type");
    if (_type == "LocalPushNotification_iOS_Permission_Status")
    {
        iOS_permission_status =  async_load[? "value"];
        switch(iOS_permission_status)
        {
            case LocalPushNotification_iOS_Permission_Status_Authorized:
                // At this point we know we have been authorized to deliver notifications to the user.
                break;
            
            case LocalPushNotification_iOS_Permission_Status_Denied:
                // At this point we know we have been denided to deliver notifications to the user.
                break;
                
            case LocalPushNotification_iOS_Permission_Status_NotDetermined:
                // At this point we know we haven't requested for permissions just yet
                // We use this logic to request for the permission.
                LocalPushNotification_iOS_Permission_Request();
                break;
        }
    }

In the example we are check the event type against the string constant LocalPushNotification_iOS_Permission_Status and subsequentialy use a switch case on the value to determine what is the current status (see PermissionStatus).

 

 

Clone this wiki locally