push_local_notification

Sets a local notification to be shown at a given time on a given date.

Syntax:

push_local_notification(fire_time, title, message, data);


Argument Description
fire_time The date/time to fire the off the notification
title The notification title (a string)
message The notification message text (a string)
data The data package to send to your game (a string)


Returns: N/A


Description

This function can be used to set a local notification to be shown on a given date at a given time. The "fire_time" is the date/time that the notification should be pushed to the user device (you can use the GameMaker: Studio Date and Time Functions to get this), and you can give the notification a title and a message text as well as a payload string which will be passed to your game when the users taps the notification.

NOTE: The "title" argument is ignored on iOS and the game name is shown instead.

Tapping the notification will start the game on the device and trigger an Asynchronous Push Notification event with a ds_map which can then be parsed to check the payload string and perform whatever action is required.

NOTE: This function is limited to the iOS and Android target modules.
IMPORTANT! For Android you will need to have installed the Google Play Services Extension and have enabled push notifications in the Android Social Global Game Settings.


Extended Example

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: Async Event in the following way:

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));
   }
else
   {
   if type == "register"
      {
      global.reg_id = ds_map_find_value(async_load, "reg_id");
      }
   else
      {
      var data = ds_map_find_value(async_load, "data");
         if data == "daily_reward"
         {
         global.Gold += 1000;
         }
      }
   }


Back: Push Notifications
Next: push_get_first_local_notification
© Copyright YoYo Games Ltd. 2018 All Rights Reserved