예제 #1
0
//Sets location trigger
    public void SetLocationTrigger()
    {
        Input.location.Start();

        var locationTrigger = new iOSNotificationLocationTrigger()
        {
            Center        = new Vector2(37.7749f, 122.4194f),
            Radius        = 5500f,
            NotifyOnEntry = true,
            NotifyOnExit  = true,
        };


        iOSNotification n = new iOSNotification()
        {
            Title                        = "Location notification ",
            Body                         = "Center: " + locationTrigger.Center.ToString() + "  Radius: " + locationTrigger.Radius.ToString(),
            Subtitle                     = "I'ma subtitle!",
            ShowInForeground             = true,
            ForegroundPresentationOption = PresentationOption.Sound | PresentationOption.Alert | PresentationOption.Badge,
            CategoryIdentifier           = "CategeoryX",
            ThreadIdentifier             = "locationNotifications",
            Trigger                      = locationTrigger,
            Badge                        = 13,
        };

        iOSNotificationCenter.ScheduleNotification(n);

        Debug.Log("Rescheduled remote notifications with id: " + n.Identifier);
    }
예제 #2
0
//Scheduling Calendar Notification
    void ScheduleCalendarNotificationIn1Minute()
    {
        Debug.Log("ScheduleCalendarNotificationIn1Minute");

        var now = DateTime.Now;

        now = now.AddMinutes(1);

        var calendarTrigger = new iOSNotificationCalendarTrigger()
        {
            Year   = now.Year,
            Month  = now.Month,
            Day    = now.Day,
            Hour   = now.Hour,
            Minute = now.Minute,
            Second = now.Second
        };


        iOSNotification n = new iOSNotification()
        {
            Title              = "ScheduleCalendarNotificationIn1Minute",
            Body               = "Scheduled at: " + DateTime.Now.ToShortDateString() + " triggered in 1 minute",
            Subtitle           = "This is a calendar notification something smth...",
            ShowInForeground   = true,
            CategoryIdentifier = "category_a",
            ThreadIdentifier   = "thread_1",
            Trigger            = calendarTrigger,
        };

        iOSNotificationCenter.ScheduleNotification(n);
    }
    public IEnumerator SendNotificationWithUserInfo_NotificationIsReceivedWithSameUserInfo()
    {
        var timeTrigger = new iOSNotificationTimeIntervalTrigger()
        {
            TimeInterval = new TimeSpan(0, 0, 5),
            Repeats      = false
        };

        var notification = new iOSNotification()
        {
            Identifier                   = "_notification_02",
            Title                        = "SendNotificationWithUserInfo_NotificationIsReceivedWithSameUserInfo",
            Body                         = "Scheduled at: " + DateTime.Now.ToShortDateString() + " triggered in 5 seconds",
            Subtitle                     = "This is a subtitle, something, something important...",
            ShowInForeground             = true,
            ForegroundPresentationOption = PresentationOption.Alert | PresentationOption.Sound,
            CategoryIdentifier           = "category_a",
            ThreadIdentifier             = "thread1",
            Trigger                      = timeTrigger,
        };

        notification.UserInfo.Add("key1", "value1");

        iOSNotificationCenter.ScheduleNotification(notification);

        yield return(WaitForNotification(10.0f));

        Assert.AreEqual(1, receivedNotificationCount);
        Assert.IsNotNull(lastReceivedNotification);
        Assert.IsTrue(lastReceivedNotification.UserInfo.ContainsKey("key1"));
        Assert.AreEqual("value1", lastReceivedNotification.UserInfo["key1"]);
    }
예제 #4
0
    //Send Simple Notification
    string SendSimpleNotification4Seconds(string title = "SendSimpleNotification4Seconds", string thread = "thread_1", bool repeat = false, int seconds = 4, int minutes = 0, PresentationOption foregroundOption = PresentationOption.Alert, int badge = -1)
    {
        Debug.Log("SendSimpleNotification4Seconds");
        var timeTrigger = new iOSNotificationTimeIntervalTrigger()
        {
            TimeInterval = new TimeSpan(0, minutes, seconds),
            Repeats      = repeat
        };

        iOSNotification n = new iOSNotification()
        {
            Title                        = title,
            Body                         = "Scheduled at: " + DateTime.Now.ToShortDateString() + " triggered in 5 seconds",
            Subtitle                     = "This is a subtitle, something, something important...",
            ShowInForeground             = true,
            ForegroundPresentationOption = foregroundOption,
            CategoryIdentifier           = "category_a",
            ThreadIdentifier             = thread,
            Trigger                      = timeTrigger,
            Data                         = "data_SendSimpleNotification4Seconds",
        };

        /* if (badge >= 0)
         *  n.Badge = badge + 1;*/

        iOSNotificationCenter.ScheduleNotification(n);

        return(n.Identifier);
    }
        void Start()
        {
            // in case a killed app was launched by clicking a notification
            iOSNotification notification  = iOSNotificationCenter.GetLastRespondedNotification();
            string          lastAction    = iOSNotificationCenter.GetLastRespondedNotificationAction();
            string          lastTextInput = iOSNotificationCenter.GetLastRespondedNotificationUserText();

            RegisterCategories();
            InstantiateAllTestButtons();
            ClearBadge();
            RemoveAllNotifications();
            m_LOGGER
            .Clear()
            .White("Welcome!");
            if (notification != null)
            {
                m_LOGGER.Green("Application launched via notification");
                if (notification.Data != "IGNORE")
                {
                    m_LOGGER
                    .Orange($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Received notification")
                    .Properties(notification, 1);
                    if (lastAction != null)
                    {
                        string output = lastTextInput != null ? $"Used action {lastAction} with input '{lastTextInput}'" : $"Used action {lastAction}";
                        m_LOGGER
                        .Orange(output);
                    }
                }
            }
        }
예제 #6
0
        private static int SendRepeatingNotification(int id, long delayMs, long timeoutMs, string title, string message, bool sound = true, bool vibrate = true, bool lights = true, string bigIcon = "", String soundName = null, string channel = "default", string imageUrl = null, params Action[] actions)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            AndroidJavaClass pluginClass = new AndroidJavaClass(fullClassName);
            if (pluginClass != null)
            {
                pluginClass.CallStatic("SetRepeatingNotification", id, delayMs, title, message, message, timeoutMs,
                                       sound ? 1 : 0, soundName, vibrate ? 1 : 0, lights ? 1 : 0, bigIcon, "notify_icon_small",
                                       bundleIdentifier, channel, PopulateActions(actions), imageUrl);
            }
            return(id);
#elif UNITY_IOS && !UNITY_EDITOR
            iOSNotification notification = new iOSNotification();
            notification.identifier = id;
            notification.message    = message;
            notification.delay      = ((double)delayMs) / 1000.0;
            notification.repeat     = CalculateiOSRepeat(timeoutMs);
            notification.category   = channel;
            notification.sound      = sound;
            notification.soundName  = soundName;
            SetActions(ref notification, actions);
            scheduleNotification(ref notification);
            return(id);
#else
            return(0);
#endif
        }
예제 #7
0
    // This function execautes once when user open the app via notificaiton
    void OpenAppViaNotification(iOSNotification ln)
    {
        // continue to play the notification sound
        iOSNotificationCalendarTrigger t = (iOSNotificationCalendarTrigger)ln.Trigger;
        // Debug.Log(System.DateTime.Now.Hour + "==" + t.Hour + "?");
        // Debug.Log(System.DateTime.Now.Minute + "==" + t.Minute + "?");
        int r = getRinger(ln.Data);

        if (System.DateTime.Now.Hour == t.Hour && System.DateTime.Now.Minute == t.Minute)
        {
            SoundPlayer.clip = Ringers[r];
            float curSec = System.DateTime.Now.Second + System.DateTime.Now.Millisecond / 1000f;
            if (curSec < SoundPlayer.clip.length)
            {
                SoundPlayer.time = curSec;
                SoundPlayer.Play();
            }
            StartAlarm((int)t.Hour, (int)t.Minute);

            // go to character's page
            int curCharacter = GetCharacterFromCategoryIdentifier(ln.CategoryIdentifier);
            CharacterSetting._ins.switchCharacter(curCharacter);
            Gamespace.Characters[curCharacter].GetComponentInChildren <CharacterSpriteManager>().showAlarm(r);
            Swipable.external_swipe_right = true;
            iOSNotificationCenter.RemoveAllDeliveredNotifications();
        }
    }
        private string IosNotify(string dateTime, string title, string subtitle, String body, bool repeats)
        {
            var dateNotify = DateTimeToNotify(dateTime);

            var calendarTrigger = new iOSNotificationCalendarTrigger()
            {
                Year    = dateNotify.Year,
                Month   = dateNotify.Month,
                Day     = dateNotify.Day,
                Hour    = dateNotify.Hour,
                Minute  = dateNotify.Minute,
                Second  = dateNotify.Second,
                Repeats = repeats
            };


            var notification = new iOSNotification()
            {
                // You can specify a custom identifier which can be used to manage the notification later.
                // If you don't provide one, a unique string will be generated automatically.

                Title                        = title,
                Body                         = body,
                Subtitle                     = subtitle,
                ShowInForeground             = true,
                ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
                CategoryIdentifier           = "category_a",
                ThreadIdentifier             = "thread1",
                Trigger                      = calendarTrigger,
            };

            iOSNotificationCenter.ScheduleNotification(notification);
            return(notification.Identifier);
        }
예제 #9
0
    public static void createNotification(string title, string body, string subtitle)
    {
        #if UNITY_IPHONE
        var timeTrigger = new iOSNotificationTimeIntervalTrigger()
        {
            TimeInterval = new TimeSpan(0, 0, 1),
            Repeats      = false
        };

        var notification = new iOSNotification()
        {
            // You can specify a custom identifier which can be used to manage the notification later.
            // If you don't provide one, a unique string will be generated automatically.
            Identifier                   = "_notification_01",
            Title                        = title,
            Body                         = body,
            Subtitle                     = subtitle,
            ShowInForeground             = true,
            ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
            CategoryIdentifier           = "category_a",
            ThreadIdentifier             = "thread1",
            Trigger                      = timeTrigger,
        };

        iOSNotificationCenter.ScheduleNotification(notification);
        #elif UNITY_ANDROID
        var notification = new AndroidNotification();
        notification.Title    = title;
        notification.Text     = subtitle;
        notification.FireTime = System.DateTime.Now;

        AndroidNotificationCenter.SendNotification(notification, "channel_id");
        #endif
    }
    public IEnumerator SendSimpleNotification_NotificationIsReceived()
    {
        var timeTrigger = new iOSNotificationTimeIntervalTrigger()
        {
            TimeInterval = new TimeSpan(0, 0, 5),
            Repeats      = false
        };

        // You can optionally specify a custom Identifier which can later be
        // used to cancel the notification, if you don't set one, an unique
        // string will be generated automatically.
        var notification = new iOSNotification()
        {
            Identifier                   = "_notification_01",
            Title                        = "SendSimpleNotification_NotificationIsReceived",
            Body                         = "Scheduled at: " + DateTime.Now.ToShortDateString() + " triggered in 5 seconds",
            Subtitle                     = "This is a subtitle, something, something important...",
            ShowInForeground             = true,
            ForegroundPresentationOption = (PresentationOption.Alert |
                                            PresentationOption.Sound),
            CategoryIdentifier = "category_a",
            ThreadIdentifier   = "thread1",
            Trigger            = timeTrigger,
        };

        iOSNotificationCenter.ScheduleNotification(notification);

        yield return(WaitForNotification(10.0f));

        Assert.AreEqual(1, receivedNotificationCount);
    }
예제 #11
0
 void OnApplicationPause(bool isPaused)
 {
     m_LOGGER
     .Gray($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Call {MethodBase.GetCurrentMethod().Name}")
     .Gray($"isPaused = {isPaused}", 1);
     if (isPaused == false)
     {
         iOSNotification notification = iOSNotificationCenter.GetLastRespondedNotification();
         if (notification != null)
         {
             m_LOGGER.Green($"Notification found:", 1);
             if (notification.Data != "IGNORE")
             {
                 m_LOGGER
                 .Orange($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Received notification")
                 .Orange($"Setting BADGE to {iOSNotificationCenter.GetDeliveredNotifications().Length + 1}", 1)
                 .Properties(notification, 1);
                 iOSNotificationCenter.ApplicationBadge =
                     iOSNotificationCenter.GetDeliveredNotifications().Length + 1;
             }
         }
         else
         {
             m_LOGGER.Red("Notification not found!", 1);
         }
     }
 }
예제 #12
0
        private string IosNotify(int delay, string title, string subtitle, String body)
        {
            var timeTrigger = new iOSNotificationTimeIntervalTrigger()
            {
                TimeInterval = new TimeSpan(0, 0, delayValue),
                Repeats      = false
            };

            var notification = new iOSNotification()
            {
                // You can specify a custom identifier which can be used to manage the notification later.
                // If you don't provide one, a unique string will be generated automatically.

                Title                        = title,
                Body                         = body,
                Subtitle                     = subtitle,
                ShowInForeground             = true,
                ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
                CategoryIdentifier           = "category_a",
                ThreadIdentifier             = "thread1",
                Trigger                      = timeTrigger,
            };

            iOSNotificationCenter.ScheduleNotification(notification);
            return(notification.Identifier);
        }
예제 #13
0
    public void NotificationExample(string title, string body, int afterTime)
    {
        var timeTrigger = new iOSNotificationTimeIntervalTrigger()
        {
            TimeInterval = new TimeSpan(0, 0, afterTime),
            Repeats      = false
        };

        iOSNotification notification = new iOSNotification()
        {
            // You can optionally specify a custom identifier which can later be
            // used to cancel the notification, if you don't set one, a unique
            // string will be generated automatically.
            Identifier                   = "_notification_01",
            Title                        = title,
            Body                         = body,
            Subtitle                     = "This is a subtitle, something, something important...",
            ShowInForeground             = false,
            ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
            CategoryIdentifier           = "category_a",
            ThreadIdentifier             = "thread1",
            Trigger                      = timeTrigger,
        };

        iOSNotificationCenter.ScheduleNotification(notification);
    }
    public static int SendNotification(int id, long delayMs, string title, string message, Color32 bgColor, bool sound = true, bool vibrate = true, bool lights = true, string bigIcon = "", string smallIcon = "", String soundName = null, string channel = "default", params Action[] actions)
    {
        if (smallIcon == "")
        {
            smallIcon = "ic_stat_mail_outline";
        }
#if UNITY_ANDROID && !UNITY_EDITOR
        AndroidJavaClass pluginClass = new AndroidJavaClass(fullClassName);
        if (pluginClass != null)
        {
            pluginClass.CallStatic("SetNotification", id, delayMs, title, message, message,
                                   sound ? 1 : 0, soundName, vibrate ? 1 : 0, lights ? 1 : 0, bigIcon, smallIcon,
                                   ToInt(bgColor), bundleIdentifier, channel, PopulateActions(actions));
        }
        return(id);
#elif UNITY_IOS && !UNITY_EDITOR
        iOSNotification notification = new iOSNotification();
        notification.identifier = id;
        notification.message    = message;
        notification.delay      = ((double)delayMs) / 1000.0;
        notification.repeat     = 0;
        notification.category   = channel;
        notification.sound      = sound;
        notification.soundName  = soundName;
        SetActions(ref notification, actions);
        scheduleNotification(ref notification);
        return(id);
#else
        return(0);
#endif
    }
        /// <summary>
        /// Check if app was opened from notification
        /// </summary>
        /// <returns>the custom data from notification schedule or null if the app was not opened from notification</returns>
        public string AppWasOpenFromNotification()
        {
#if EnableNotificationsAndroid
            var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();

            if (notificationIntentData != null)
            {
                return(notificationIntentData.Notification.IntentData);
            }
            else
            {
                return(null);
            }
#elif EnableNotificationsIos
            iOSNotification notificationIntentData = iOSNotificationCenter.GetLastRespondedNotification();

            if (notificationIntentData != null)
            {
                return(notificationIntentData.Data);
            }
            else
            {
                return(null);
            }
#else
            return(null);
#endif
        }
    /// <summary>
    /// Send a notification using DELTADNA Event Triggered campaign
    /// </summary>
    /// <param name="gameParameters"></param>
    public void SendDDNANotification(Dictionary <string, object> gameParameters)
    {
        //Prepare the unity mobile notificaitons
        notificationID = Convert.ToInt32(gameParameters["notificationId"]); //SET notification Id else comment this line to let the packagage generate one
#if UNITY_ANDROID
        var notification = new AndroidNotification();
        notification.IntentData = "{\"campaignId\": \"id 1\", \"campaignName\": \"name\",\"notificationId\": \"id 1\",}";
        notification.SmallIcon  = "my_custom_icon_id";
        notification.LargeIcon  = "my_custom_large_icon_id";
        notification.Title      = gameParameters["localNotifTitle"].ToString();
        notification.Text       = gameParameters["localNotifDesc"].ToString();
        notification.FireTime   = System.DateTime.Now.AddMinutes(Convert.ToDouble(gameParameters["localNotifTime"]));

        //Send the notification with unity mobile notifications
        AndroidNotificationCenter.SendNotificationWithExplicitID(notification, "channel_id", notificationID);
#elif UNITY_IOS
        var             notification = new iOSNotification();
        System.DateTime date         = System.DateTime.Now.AddMinutes(Convert.ToDouble(gameParameters["localNotifTime"]));

        notification.Identifier = notificationID.ToString();
        notification.Title      = gameParameters["localNotifTitle"].ToString();
        notification.Body       = gameParameters["localNotifDesc"].ToString();
        notification.Trigger    = notification.Trigger = new iOSNotificationCalendarTrigger
        {
            Year   = date.Year,
            Month  = date.Month,
            Day    = date.Day,
            Hour   = date.Hour,
            Minute = date.Minute,
            Second = date.Second
        };
        notification.CategoryIdentifier = "GOLD_REWARD";

        //Send the notification with unity mobile notifications
        iOSNotificationCenter.ScheduleNotification(notification);
        Debug.Log("Sceduled Notification");
#endif

        //Record the event for reporting services
        GameEvent localNotifications = new GameEvent("localNotifications");
        localNotifications.AddParam("notificationId", Convert.ToInt32(gameParameters["notificationId"]));
        localNotifications.AddParam("campaignId", Convert.ToInt32(gameParameters["campaignId"]));
        localNotifications.AddParam("campaignName", gameParameters["campaignName"].ToString());
        localNotifications.AddParam("cohortId", Convert.ToInt32(gameParameters["cohortId"]));
        localNotifications.AddParam("cohortName", gameParameters["cohortName"].ToString());
        localNotifications.AddParam("communicationSender", "Unity Mobile Notifications");
        localNotifications.AddParam("communicationState", "SENT");
        localNotifications.AddParam("localNotifTitle", notification.Title);

#if UNITY_IOS
        localNotifications.AddParam("localNotifDesc", notification.Body);
#elif UNITY_ANDROID
        localNotifications.AddParam("localNotifDesc", notification.Text);
#endif
        localNotifications.AddParam("localNotifTime", Convert.ToInt32(gameParameters["localNotifTime"]));

        // Record the missionStarted event event with some event parameters.
        DDNA.Instance.RecordEvent(localNotifications).Run();
    }
예제 #17
0
 void OnNotificationReceivedHandler(iOSNotification notification)
 {
     m_LOGGER
     .Orange($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Received a notification")
     .Orange($"Setting BADGE to {iOSNotificationCenter.GetDeliveredNotifications().Length + 1}", 1)
     .Properties(notification, 1);
     // Update badge
     iOSNotificationCenter.ApplicationBadge = iOSNotificationCenter.GetDeliveredNotifications().Length + 1;
 }
    /// <summary>
    /// 通知共通生成処理。
    /// </summary>
    /// <param name="title">タイトル。</param>
    /// <param name="detail">詳細。</param>
    /// <param name="identifier">識別子。</param>
    /// <returns>通知データ。</returns>
    static iOSNotification CreateCommonNotification(string title, string detail, string identifier)
    {
        // 通知を作成。
        var notification = new iOSNotification();

        notification.Title      = title;
        notification.Body       = detail;
        notification.Identifier = identifier;
        return(notification);
    }
예제 #19
0
    private void Start()
    {
        iOSNotificationTimeIntervalTrigger timeTrigger = new iOSNotificationTimeIntervalTrigger()
        {
            TimeInterval = new TimeSpan(0, 0, 10),
            Repeats      = false,
        };

        iOSNotificationCalendarTrigger calendarTrigger = new iOSNotificationCalendarTrigger()
        {
            // Year = 2019,
            // Month = 8,
            //Day = 30,
            Hour   = 12,
            Minute = 0,
            // Second = 0
            Repeats = false
        };

        iOSNotificationLocationTrigger locationTrigger = new iOSNotificationLocationTrigger()
        {
            Center        = new Vector2(2.294498f, 48.858263f),
            Radius        = 250f,
            NotifyOnEntry = true,
            NotifyOnExit  = false,
        };

        iOSNotification notification = new iOSNotification()
        {
            Identifier                   = "test_notification",
            Title                        = "Test Notification!",
            Subtitle                     = "A Unity Royale Test Notification",
            Body                         = "This is a test notification!",
            ShowInForeground             = true,
            ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
            CategoryIdentifier           = "category_a",
            ThreadIdentifier             = "thread1",
            Trigger                      = timeTrigger,
        };

        iOSNotificationCenter.ScheduleNotification(notification);

        iOSNotificationCenter.OnRemoteNotificationReceived += recievedNotification =>
        {
            Debug.Log("Recieved notification " + notification.Identifier + "!");
        };


        iOSNotification notificationIntentData = iOSNotificationCenter.GetLastRespondedNotification();

        if (notificationIntentData != null)
        {
            Debug.Log("App was opened with notification!");
        }
    }
예제 #20
0
 public iOSNotification ScheduleNotification(iOSNotification notification, bool log = true)
 {
     if (log)
     {
         m_LOGGER
         .Blue($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Call {MethodBase.GetCurrentMethod().Name}")
         .Properties(notification);
     }
     iOSNotificationCenter.ScheduleNotification(notification);
     return(notification);
 }
예제 #21
0
        public void SetupFullEnergyNotification(int hours, int minutes, int seconds)
        {
            if (_isPushNotificationsEnable == false)
            {
                return;
            }

#if UNITY_IOS
            iOSNotificationCenter.RemoveScheduledNotification(_fullEnergyNotificationID);
            iOSNotificationTimeIntervalTrigger timeTrigger = new iOSNotificationTimeIntervalTrigger()
            {
                TimeInterval = new TimeSpan(hours, minutes, seconds),
                Repeats      = false
            };

            iOSNotification notification = new iOSNotification()
            {
                Identifier                   = _fullEnergyNotificationID,
                Title                        = SimpleLocalization.LocalizationManager.Localize("PrPol.FullEnT"),
                Body                         = SimpleLocalization.LocalizationManager.Localize("PrPol.FullEnD"),
                ShowInForeground             = true,
                ForegroundPresentationOption = PresentationOption.Alert | PresentationOption.Sound,
                Trigger                      = timeTrigger,
            };

            iOSNotificationCenter.ScheduleNotification(notification);
#endif

#if UNITY_ANDROID
            AndroidNotificationCenter.DeleteNotificationChannel(_fullEnergyNotificationID);
            AndroidNotificationCenter.CancelScheduledNotification(_energyNotification);
            AndroidNotificationChannel anc = new AndroidNotificationChannel()
            {
                Id          = _fullEnergyNotificationID,
                Name        = "fullenergyNotification",
                Importance  = Importance.High,
                Description = "Generic notifications",
            };

            AndroidNotificationCenter.RegisterNotificationChannel(anc);

            AndroidNotification notification = new AndroidNotification
            {
                Title     = SimpleLocalization.LocalizationManager.Localize("PrPol.FullEnT"),
                Text      = SimpleLocalization.LocalizationManager.Localize("PrPol.FullEnD"),
                FireTime  = DateTime.Now.Add(new TimeSpan(hours, minutes, seconds)),
                SmallIcon = "daily_reward_icon_small",
                LargeIcon = "daily_reward_icon_large"
            };

            _energyNotification = AndroidNotificationCenter.SendNotification(notification, _fullEnergyNotificationID);
#endif
        }
        /// <summary>
        /// Schedules a notification
        /// </summary>
        /// <param name="title">title of the notification</param>
        /// <param name="text">body of the notification</param>
        /// <param name="timeDelayFromNow">time to appear, calculated from now</param>
        /// <param name="smallIcon">small icon name for android only - from Mobile Notification Settings </param>
        /// <param name="largeIcon">large icon name for android only - from Mobile Notification Settings </param>
        /// <param name="customData">custom data that can be retrieved when user opens the app from notification </param>
        internal void SendNotification(string title, string text, TimeSpan timeDelayFromNow, string smallIcon, string largeIcon, string customData)
        {
#if EnableNotificationsAndroid
            var notification = new AndroidNotification();
            notification.Title = title;
            notification.Text  = text;
            if (smallIcon != null)
            {
                notification.SmallIcon = smallIcon;
            }
            if (smallIcon != null)
            {
                notification.LargeIcon = largeIcon;
            }
            if (customData != null)
            {
                notification.IntentData = customData;
            }
            notification.FireTime = DateTime.Now.Add(timeDelayFromNow);

            AndroidNotificationCenter.SendNotification(notification, channelID + count);
#endif

#if EnableNotificationsIos
            print("I am Notification Manager");
            iOSNotificationTimeIntervalTrigger timeTrigger = new iOSNotificationTimeIntervalTrigger()
            {
                TimeInterval = timeDelayFromNow,
                Repeats      = false,
            };

            iOSNotification notification = new iOSNotification()
            {
                Identifier                   = channelID + count,
                Title                        = title,
                Subtitle                     = "Time To Meditate",
                Body                         = text,
                Data                         = customData,
                ShowInForeground             = true,
                ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
                CategoryIdentifier           = "category_a",
                ThreadIdentifier             = "thread1",
                Trigger                      = timeTrigger,
            };
            if (AlarmClockMenuEventListerner.instance.newAlarm)
            {
                AlarmClockMenuEventListerner.instance.ChannelId.Add(notification.Identifier);
                count++;
            }
            iOSNotificationCenter.ScheduleNotification(notification);
#endif
        }
예제 #23
0
    // This function execautes once when user receive notificaiton when app is already open
    void OnNotificationReceived(iOSNotification ln)
    {
        // play character voice
        int r = getRinger(ln.Data);

        SoundPlayer.clip = Ringers[r];
        SoundPlayer.Play();
        StartAlarm(System.DateTime.Now.Hour, System.DateTime.Now.Minute);
        int curCharacter = GetCharacterFromCategoryIdentifier(ln.CategoryIdentifier);

        CharacterSetting._ins.switchCharacter(curCharacter);
        Gamespace.Characters[curCharacter].GetComponentInChildren <CharacterSpriteManager>().showAlarm(r);
        Swipable.external_swipe_right = true;
        Handheld.Vibrate();
    }
 public void BeforeTests()
 {
     iOSNotificationCenter.OnNotificationReceived += receivedNotification =>
     {
         receivedNotificationCount += 1;
         lastReceivedNotification   = receivedNotification;
         var msg = "Notification received : " + receivedNotification.Identifier + "\n";
         msg += "\n Notification received: ";
         msg += "\n .Title: " + receivedNotification.Title;
         msg += "\n .Badge: " + receivedNotification.Badge;
         msg += "\n .Body: " + receivedNotification.Body;
         msg += "\n .CategoryIdentifier: " + receivedNotification.CategoryIdentifier;
         msg += "\n .Subtitle: " + receivedNotification.Subtitle;
         Debug.Log(msg);
     };
 }
예제 #25
0
    void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(this.gameObject);
            return;
        }
        else
        {
            instance = this;
        }
        DontDestroyOnLoad(this.gameObject);

        UnityEngine.iOS.NotificationServices.RegisterForNotifications(
            UnityEngine.iOS.NotificationType.Alert |
            UnityEngine.iOS.NotificationType.Badge |
            UnityEngine.iOS.NotificationType.Sound);
    }
예제 #26
0
        public void scheduleLocalNotification(LocalNotificationData notificationData)
        {
            if (!isInitialized)
            {
                return;
            }
            var timeSpan    = TimeExtensions.hoursToTimeSpan(notificationData.triggerInHours);
            var timeTrigger = new iOSNotificationTimeIntervalTrigger()
            {
                TimeInterval = timeSpan,
                Repeats      = notificationData.isRepeatingNotification
            };

            notificationData.utcScheduledTime = TimeExtensions.currentUtcTime.Add(timeSpan);
            iOSNotification notification = createNotification(notificationData, timeTrigger);

            iOSNotificationCenter.ScheduleNotification(notification);
        }
예제 #27
0
        void OnNotificationReceivedHandler(iOSNotification notification)
        {
            m_LOGGER
            .Orange($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Received a notification")
            .Orange($"Setting BADGE to {iOSNotificationCenter.GetDeliveredNotifications().Length + 1}", 1)
            .Properties(notification, 1);

            if (notification.UserInfo.Count > 3)
            {
                m_LOGGER.Orange("Received user info:");
                foreach (var item in notification.UserInfo)
                {
                    m_LOGGER.Gray($"{item.Key}: {item.Value}");
                }
            }

            // Update badge
            iOSNotificationCenter.ApplicationBadge = iOSNotificationCenter.GetDeliveredNotifications().Length + 1;
        }
예제 #28
0
 internal static void SetActions(ref iOSNotification notification, Action[] actions)
 {
     notification.actionCount = actions.Length;
     if (actions.Length > 0)
     {
         notification.action1 = CreateAction(actions[0]);
     }
     if (actions.Length > 1)
     {
         notification.action2 = CreateAction(actions[1]);
     }
     if (actions.Length > 2)
     {
         notification.action3 = CreateAction(actions[2]);
     }
     if (actions.Length > 3)
     {
         notification.action4 = CreateAction(actions[3]);
     }
 }
예제 #29
0
        private static iOSNotification createNotification(LocalNotificationData notificationData, iOSNotificationTimeIntervalTrigger timeTrigger)
        {
            var notification = new iOSNotification()
            {
                // You can optionally specify a custom Identifier which can later be
                // used to cancel the notification, if you don't set one, an unique
                // string will be generated automatically.
                Identifier                   = notificationData.id.ToString(),
                Title                        = notificationData.title,
                Body                         = notificationData.text,
                Subtitle                     = "",
                ShowInForeground             = true,
                ForegroundPresentationOption = PresentationOption.NotificationPresentationOptionAlert,
                CategoryIdentifier           = Application.productName,
                //ThreadIdentifier = thread,
                Trigger = timeTrigger,
            };

            return(notification);
        }
예제 #30
0
        void OnRemoteNotificationReceivedHandler(iOSNotification notification)
        {
            m_LOGGER
            .Orange($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Received a remote notification")
            .Orange($"Setting BADGE to {iOSNotificationCenter.GetDeliveredNotifications().Length + 1}", 1)
            .Red($"It will not show up in foreground and it will trigger OnNotificationReceived callback, that is by design")
            .Properties(notification, 1);
            // Application still receives OnNotificationReceived callback which updates the badge
            // iOSNotificationCenter.ApplicationBadge = iOSNotificationCenter.GetDeliveredNotifications().Length + 1;

            // If we want to show this remote notification in foreground, we have to reschedule it locally

            /* m_LOGGER
             *  .Separator()
             *  .Orange($"Rescheduling remote notification to be sent in 1 second", 1);
             * iOSNotificationTimeIntervalTrigger newTrigger = new iOSNotificationTimeIntervalTrigger(){ TimeInterval = new TimeSpan(0, 0, 1) };
             * notification.Trigger = newTrigger;
             * notification.ShowInForeground = true;
             * iOSNotificationCenter.ScheduleNotification(notification); */
        }