Unity3d IOS Local message notification localnotification use __ios

Source: Internet
Author: User
Tags datetime

The game now usually has local news, such as 12 or 6 o'clock in the afternoon every day to tell players to enter the game to collect physical strength. This kind of thing does not need the server to push, the client can complete. Unity inside provides the functionality of the local tasks but only iOS support, I started a bit puzzled why Android does not support, when I finished the local Android notice, I do not understand. The iOS source API supports a fixed-time loop push, and Android needs to start a services on its own, starting a Alarmmanager timer task, but I've developed Android before, and today we'll talk about local notifications on iOS.

the code is actually very simple, I'll say the following principle gives the implementation steps.

1. Register local notification when the game goes backstage

2. Turn off local alerts when the game enters the foreground

the code below. C #

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67-68 Using Unityengine; Using System. collections;   public class Newbehaviourscript:monobehaviour {    /local push      public static void Notificationmessage (string message, int hour, bool isrepeatday)      {  &N bsp;      int year = System. Datetime. Now. year;          int month = System. Datetime. Now. Month;          int day = System. Datetime. Now. Day;          System. DateTime newdate = new System. DateTime (year, month, day, hour, 0, 0);          notificationmessage (Message, newdate, isrepeatday);     }     //Local push you can pass in a fixed push time      public static void Notificationmessage (String message, System. DateTime Newdate, BOOL IsrepeAtday)      {        //push time required is greater than the current time           if (Newdate > System. Datetime. Now)          {              localnotification localnotification = new Localnotification ();              localnotification. Firedate = newdate;                   Localnotification. alertbody = message;              localnotification. Applicationiconbadgenumber = 1;              localnotification. Hasaction = true;              if (isrepeatday)               {                 /Whether regular daily cycle                   localnotification. Repeatcalendar = Calendaridentifier. Chinesecalendar;                  Localnotification. Repeatinterval = Calendarunit. Day;             }               localnotification. Soundname = localnotification. Defaultsoundname;              NotificationServices. Schedulelocalnotification (localnotification);         }     }        void Awake ()      {        //The first time to enter the game when empty, it is possible that the user himself to the game to kill the background, here forced to empty           cleannotification ();     }        void Onapplicationpause (bool paused)    & nbsp {        //when the program goes backstage          if ( Paused)          {             //10 seconds to send              Notificationmessage ("Rain loose momo:10 seconds after sending", System. Datetime. Now. AddSeconds (a), false);             /daily 12 o'clock noon push               notificationmessage ("Rain pine Momo: Push every day 12 o'clock Noon", true);         }     &Nbsp;    Else          {             //procedure from backstage to front desk               cleannotification ();         }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.