push_local_notification


描述

此函数用于设置一个给定时间日期的本地通知。The "fire_time" is the date/time that the notification should be pushed to the user device (you can use the GameMaker Studio 2 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.

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


点击通知将会启动游戏同时触发 异步推送通知(Asynchronous Push Notification)事件并返回 ds_map ,检查扩展数据的字符串来采取你想要的动作处理这个事件。

注意: This function is limited to the iOS and Android target modules. For Android you will need to have installed the Google Play Services Extension and have enabled push notifications in the Android Social Game Options.


语法:

push_local_notification(fire_time, title, message, data);

参数 描述
fire_time 触发通知的日期/时间。
title 通知的标题 (字符串格式)
message 通知的正文(字符串格式)
data 发送到游戏的数据包 (字符串格式)


Returns:

N/A(无返回值)


扩展示例

在这个示例中,我们将使用下面的代码来发送一个本地推送通知:

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);

设置一个计时器在一天后向设备 “推送” 一个通知。一天以后,无论你的程序是在后台还是未启动状态,玩家都将收到之前设置的通知(在 iOS 平台标题被游戏的名字替代),然后一个异步的推送通知事件(Push Notification Event)会被触发。需要注意的是,如果推送时程序运行在前台,通知将 不会 被展示,但是异步推送事件 仍会触发。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;
         }
      }
   }