コード例 #1
0
ファイル: IOSManagerImpl.cs プロジェクト: ryan-ash/ld44-coin
        public override bool SetPushNotificationsEnabled(bool enabled)
        {
            // Should be done before (enable == m_pushEnabled) check in order to disable push notifications before Manager initialization
            UnityEngine.PlayerPrefs.SetInt(m_pushEnabledOptionName, enabled ? 1 : 0);

            if (enabled && !Settings.Instance.PushNotificationsEnabledIOS)
            {
                UnityEngine.Debug.LogWarning("Can't enable push notifications: iOS -> Push Notifications are disabled in the UTNotifications Settings");
            }

            if (!Initialized || enabled == m_pushEnabled)
            {
                return(PushNotificationsEnabled());
            }

            m_pushEnabled = enabled;

            if (m_enabled && Settings.Instance.PushNotificationsEnabledIOS)
            {
                if (m_pushEnabled)
                {
                    RegisterForNotifications();
                }
                else
                {
                    NotificationServices.UnregisterForRemoteNotifications();
                }
            }

            return(PushNotificationsEnabled());
        }
コード例 #2
0
 /// <summary>
 /// Unregisters for push notifications.
 /// </summary>
 public void UnregisterForPushNotifications()
 {
     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {
     #if UNITY_IPHONE
     #if UNITY_4_5 || UNITY_4_6 || UNITY_4_7
         NotificationServices.UnregisterForRemoteNotifications();
     #else
         UnityEngine.iOS.NotificationServices.UnregisterForRemoteNotifications();
     #endif
     #endif
     }
 }
コード例 #3
0
 public static void unRegisterForPushNotification()
 {
     NotificationServices.UnregisterForRemoteNotifications();
 }
コード例 #4
0
ファイル: IOSManagerImpl.cs プロジェクト: ryan-ash/ld44-coin
        //private
        private void SetNotificationsEnabled(bool enabled, bool inInitialization)
        {
            UnityEngine.PlayerPrefs.SetInt(m_enabledOptionName, enabled ? 1 : 0);

            if (!inInitialization && !Initialized)
            {
                if (!enabled)
                {
                    NotificationServices.UnregisterForRemoteNotifications();
                }

                return;
            }

            if (m_enabled == enabled)
            {
                return;
            }

            m_enabled = enabled;

            if (enabled)
            {
                RegisterForNotifications();

                if (m_scheduledNotificationsWhenDisabled != null)
                {
                    DateTime now = DateTime.Now;

                    foreach (var scheduledNotification in m_scheduledNotificationsWhenDisabled)
                    {
                        LocalNotification notification = new LocalNotification();
                        if (scheduledNotification.badgeNumber >= 0)
                        {
                            notification.applicationIconBadgeNumber = scheduledNotification.badgeNumber;
                        }
                        notification.alertAction = scheduledNotification.alertAction;
                        notification.alertBody   = scheduledNotification.alertBody;
                        notification.hasAction   = true;
                        notification.soundName   = scheduledNotification.soundName;
                        notification.userInfo    = (scheduledNotification.userData != null) ? scheduledNotification.userData : new Dictionary <string, string>();
                        if (scheduledNotification.fireDate > now)
                        {
                            notification.fireDate = scheduledNotification.fireDate;
                        }
                        else if (scheduledNotification.fireDate != DateTime.MinValue)
                        {
                            notification.fireDate = DateTime.Now.AddSeconds(2);
                        }
                        else
                        {
                            notification.fireDate = RepeatIntervalToDateTime(scheduledNotification.repeatInterval);
                        }
                        notification.repeatInterval = scheduledNotification.repeatInterval;

                        NotificationServices.ScheduleLocalNotification(notification);
                    }

                    m_scheduledNotificationsWhenDisabled = null;
                    SaveScheduledNotificationsWhenDisabled();
                }

                if (!inInitialization)
                {
                    SetBadge(GetBadge());
                }
            }
            else
            {
                List <ScheduledNotification> scheduledNotificationsWhenDisabled;
                if (NotificationServices.scheduledLocalNotifications != null && NotificationServices.scheduledLocalNotifications.Length != 0)
                {
                    scheduledNotificationsWhenDisabled = new List <ScheduledNotification>(NotificationServices.scheduledLocalNotifications.Length);

                    DateTime now = DateTime.Now;

                    foreach (var notification in NotificationServices.scheduledLocalNotifications)
                    {
                        scheduledNotificationsWhenDisabled.Add(ToScheduledNotification(notification, now));
                    }
                }
                else
                {
                    scheduledNotificationsWhenDisabled = null;
                }

                CancelAllNotifications();
                NotificationServices.UnregisterForRemoteNotifications();

                if (scheduledNotificationsWhenDisabled != null)
                {
                    m_scheduledNotificationsWhenDisabled = scheduledNotificationsWhenDisabled;
                    SaveScheduledNotificationsWhenDisabled();
                }

                _UT_SetIconBadgeNumber(0);
            }
        }