Push Notification Event

This is the sub event that will be triggered by any of the push notification functions.

The Push Notification Event is one that is triggered by the call back from push notifications on the device OS, either from a local source using the function push_local_notification, or from a remote source (ie: your server). It generates a ds_map (more commonly known as a "dictionary") that is exclusive to this event and is stored in the special variable async_load (please see the individual functions that trigger asynchronous events for code examples that explain the use of this event in further detail). This ds_map has the following keys:

  1. "type": Value can be "local" for a device local notification, "remote" for a remote notification, or "register" for remote notification registration.
  2. "status": Value will be "1" for success or "0" for an error.

There may be additional key entries based on the "type" returned and the "status" value. For "status", if an error has been returned ("0"), then you will also have the following key:

  1. "error": Contains details of the error received.

If the "status" value is 0 (ie: no errors) then the ds_map will contain the following additional values, depending on the value of the "type" key:

  1. "reg_id": If the "type" received was "register", then this key will hold the device registration id for remote notifications.
  2. "data": If the "type" received was "local" or "remote", then this key will hold the string payload that you defined when you called the notification function.

Example of Use

In this example we will send a local push notification using the following code:

var fireTime = date_inc_day(date_current_datetime(), 1);
var data = "daily_reward";
push_local_notification(fireTime, "Ahoy!", "Catch The Haggis Has A Present", data);

This will set a timer to "push" a notification to the device when one day has passed. When the day is up, if your game is either in the background or not running, a notification will be shown to the user with the given title and message (on iOS, the game name is shown and the title is ignored), and then an asynchronous Push Notification Event will be called. Note that if the game is in the foreground when the time for the notification comes, it will not be shown, but the asynchronous event will still trigger. In the event itself you would handle the callback something like this:

var type = ds_map_find_value(async_load, "type");
var status = ds_map_find_value(async_load, "status");
if status == 0
   //error of some kind
   var error = ds_map_find_value(async_load, "error");
   show_debug_message("error=" + string(error));
   if type == "register"
      global.reg_id = ds_map_find_value(async_load, "reg_id");
      var data = ds_map_find_value(async_load, "data");
         if data == "daily_reward"
         global.Gold += 1000;

NOTE: The variable async_load is only valid in these events, as the ds_map that is points to is created at the start of the event, then deleted again at the end, with this variable being reset to a value of -1.

Back: More About Async Events
Next: Load And Save Events
© Copyright YoYo Games Ltd. 2015 All Rights Reserved