Exemplo n.º 1
0
        private void HandleReceivedNotifications(string receivedNotificationsPacked)
        {
            if (string.IsNullOrEmpty(receivedNotificationsPacked) || receivedNotificationsPacked == "[]")
            {
                return;
            }
            List <ReceivedNotification> list = new List <ReceivedNotification>();
            JSONNode jSONNode = JSON.Parse(receivedNotificationsPacked);

            for (int i = 0; i < jSONNode.Count; i++)
            {
                ReceivedNotification receivedNotification = ParseReceivedNotification(jSONNode[i]);
                bool flag = false;
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j].id == receivedNotification.id)
                    {
                        list[j] = receivedNotification;
                        flag    = true;
                        break;
                    }
                }
                if (!flag)
                {
                    list.Add(receivedNotification);
                }
            }
            _OnNotificationsReceived(list);
        }
Exemplo n.º 2
0
 private void HandleReceivedNotifications(string receivedNotificationsPacked)
 {
     if (!string.IsNullOrEmpty(receivedNotificationsPacked) && (receivedNotificationsPacked != "[]"))
     {
         List <ReceivedNotification> receivedNotifications = new List <ReceivedNotification>();
         JSONNode node = JSON.Parse(receivedNotificationsPacked);
         for (int i = 0; i < node.Count; i++)
         {
             JSONNode             json = node[i];
             ReceivedNotification item = this.ParseReceivedNotification(json);
             bool flag = false;
             for (int j = 0; j < receivedNotifications.Count; j++)
             {
                 if (receivedNotifications[j].id == item.id)
                 {
                     receivedNotifications[j] = item;
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 receivedNotifications.Add(item);
             }
         }
         base._OnNotificationsReceived(receivedNotifications);
     }
 }
Exemplo n.º 3
0
        private ReceivedNotification ToReceivedNotification(RemoteNotification notification)
        {
            Dictionary <string, string> userData = UserInfoToDictionaryOfStrings(notification.userInfo);

            if (userData != null && userData.ContainsKey(m_idKeyName))
            {
                userData.Remove(m_idKeyName);
            }

            int id = ExtractId(notification.userInfo);

            string title, text;

#if UNITY_2018_2_OR_NEWER
            title = notification.alertTitle;
            text  = notification.alertBody;
#else
            ExtractTitleAndText(notification.alertBody, out title, out text);
#endif

            ReceivedNotification receivedNotification = new ReceivedNotification(title, text, id >= 0 ? id : m_nextPushNotificationId, userData, ExtractNotificationProfile(notification.soundName), notification.applicationIconBadgeNumber);

            if (id < 0 && m_incrementalId)
            {
                ++m_nextPushNotificationId;
            }

            return(receivedNotification);
        }
 public void OnReceived(ReceivedNotification received)
 {
     this.received.Add(received);
     if (clicked == null && this.received.Count == 1)
     {
         UpdateContents();
     }
 }
 public void Hide(int id)
 {
     if (clicked != null && clicked.id == id)
     {
         clicked = null;
     }
     received.RemoveAll((ReceivedNotification it) => it.id == id);
     UpdateContents();
 }
        private void UpdateContents()
        {
            ReceivedNotification current = Current;

            if (current == null)
            {
                base.gameObject.SetActive(value: false);
                return;
            }
            DialogTitle.text = ((current == clicked) ? "Notification Clicked" : "Notification Received");
            ID.text          = current.id.ToString();
            Title.text       = current.title;
            Text.text        = current.text;
            Profile.text     = (current.notificationProfile ?? "");
            UserData.text    = UserDataString(current.userData);
            Badge.text       = ((current.badgeNumber != -1) ? current.badgeNumber.ToString() : "");
            base.gameObject.SetActive(value: true);
        }
        private void HandleReceivedNotifications(string receivedNotificationsPacked)
        {
            if (string.IsNullOrEmpty(receivedNotificationsPacked) || receivedNotificationsPacked == "[]")
            {
                return;
            }

            List <ReceivedNotification> receivedNotifications = new List <ReceivedNotification>();

            JSONNode notificationsList = JSON.Parse(receivedNotificationsPacked);

            for (int i = 0; i < notificationsList.Count; ++i)
            {
                JSONNode json = notificationsList[i];

                ReceivedNotification receivedNotification = ParseReceivedNotification(json);

                //Update out-of-date notifications
                bool updated = false;
                for (int j = 0; j < receivedNotifications.Count; ++j)
                {
                    if (receivedNotifications[j].id == receivedNotification.id)
                    {
                        receivedNotifications[j] = receivedNotification;
                        updated = true;
                        break;
                    }
                }
                if (!updated)
                {
                    receivedNotifications.Add(receivedNotification);
                }
            }

            _OnNotificationsReceived(receivedNotifications);
        }
Exemplo n.º 8
0
 protected void _OnNotificationClicked(ReceivedNotification notification)
 {
     this.OnNotificationClicked(notification);
 }
 protected void OnNotificationClicked(ReceivedNotification notification)
 {
     NotificationDetailsDialog.OnClicked(notification);
 }
 public void CancelAll()
 {
     clicked = null;
     received.Clear();
     UpdateContents();
 }
        public void Cancel()
        {
            ReceivedNotification current = Current;

            UTNotificationsSample.Instance.Cancel(current.id);
        }
        public void Hide()
        {
            ReceivedNotification current = Current;

            UTNotificationsSample.Instance.Hide(current.id);
        }
 public void OnClicked(ReceivedNotification clicked)
 {
     this.clicked = clicked;
     UpdateContents();
 }
Exemplo n.º 14
0
        //protected
        protected void LateUpdate()
        {
            if (!Initialized)
            {
                return;
            }

            if (m_initRemoteNotifications)
            {
                if (!string.IsNullOrEmpty(NotificationServices.registrationError))
                {
                    m_initRemoteNotifications = false;
                    UnityEngine.Debug.LogError("iOS Push Notifications initialization error: " + NotificationServices.registrationError);
                }
                else if (NotificationServices.deviceToken != null && NotificationServices.deviceToken.Length > 0 && OnSendRegistrationIdHasSubscribers())
                {
                    m_initRemoteNotifications = false;
                    _OnSendRegistrationId(m_providerName, ByteArrayToHexString(NotificationServices.deviceToken));
                }
            }

            CleanupDuplications();

            //Handle received/clicked notifications
            int localCount  = (NotificationServices.localNotifications != null) ? NotificationServices.localNotifications.Length : 0;
            int remoteCount = (NotificationServices.remoteNotifications != null) ? NotificationServices.remoteNotifications.Length : 0;

            List <ReceivedNotification> list;

            if ((localCount > 0 || remoteCount > 0) && m_willHandleReceivedNotifications && OnNotificationsReceivedHasSubscribers())
            {
                list = new List <ReceivedNotification>(localCount + remoteCount);
            }
            else
            {
                list = null;
            }

            if (list == null && !OnNotificationClickedHasSubscribers())
            {
                return;
            }

            if (localCount > 0)
            {
                foreach (var notification in NotificationServices.localNotifications)
                {
                    ReceivedNotification receivedNotification = null;

                    //Check if the notification was clicked
                    if (OnNotificationClickedHasSubscribers())
                    {
                        int id = ExtractId(notification.userInfo);

                        if (_UT_LocalNotificationWasClicked(id))
                        {
                            receivedNotification = ToReceivedNotification(notification);
                            _OnNotificationClicked(receivedNotification);

                            if (list == null)
                            {
                                break;
                            }
                        }
                    }

                    if (list != null)
                    {
                        if (receivedNotification == null)
                        {
                            receivedNotification = ToReceivedNotification(notification);
                        }

                        list.Add(receivedNotification);
                    }
                }
            }

            if (remoteCount > 0)
            {
                foreach (var notification in NotificationServices.remoteNotifications)
                {
                    ReceivedNotification receivedNotification = null;

                    //Check if the notification was clicked
                    if (OnNotificationClickedHasSubscribers() && _UT_PushNotificationWasClicked(notification.alertBody))
                    {
                        receivedNotification = ToReceivedNotification(notification);
                        _OnNotificationClicked(receivedNotification);

                        if (list == null)
                        {
                            break;
                        }
                    }

                    if (list != null)
                    {
                        if (receivedNotification == null)
                        {
                            receivedNotification = ToReceivedNotification(notification);
                        }

                        list.Add(receivedNotification);
                    }
                }
            }

            if (list != null && list.Count > 0)
            {
                HideAllNotifications();
                _OnNotificationsReceived(list);
            }
        }