Ejemplo n.º 1
0
    public CrossPlatformNotification CreateNotification(string title, long fireAfterSec,
                                                        eNotificationRepeatInterval repeatInterval)
    {
        // User info
        IDictionary userInfo = new Dictionary <string, string>();

        // userInfo["data"] = "custom data";

        CrossPlatformNotification.iOSSpecificProperties _iosProperties =
            new CrossPlatformNotification.iOSSpecificProperties();
        _iosProperties.HasAction   = false;
        _iosProperties.AlertAction = null;

        CrossPlatformNotification.AndroidSpecificProperties _androidProperties =
            new CrossPlatformNotification.AndroidSpecificProperties();
        _androidProperties.ContentTitle = title;
        _androidProperties.TickerText   = title;
        _androidProperties.LargeIcon    =
            "App-Icon.png"; //Keep the files in Assets/PluginResources/Android or Common folder.

        CrossPlatformNotification notification = new CrossPlatformNotification();

        notification.AlertBody      = title; //On Android, this is considered as ContentText
        notification.FireDate       = DateTime.Now.AddSeconds(fireAfterSec);
        notification.RepeatInterval = repeatInterval;
        notification.SoundName      =
            "Notification.mp3"; //Keep the files in Assets/PluginResources/Android or iOS or Common folder.
        notification.UserInfo          = userInfo;
        notification.iOSProperties     = _iosProperties;
        notification.AndroidProperties = _androidProperties;

        return(notification);
    }
        private CrossPlatformNotification CreateNotification(long _fireAfterSec, eNotificationRepeatInterval _repeatInterval)
        {
            // User info
            IDictionary _userInfo = new Dictionary <string, string>();

            _userInfo["data"] = "custom data";

            CrossPlatformNotification.iOSSpecificProperties _iosProperties = new CrossPlatformNotification.iOSSpecificProperties();
            _iosProperties.HasAction   = true;
            _iosProperties.AlertAction = "alert action";

            CrossPlatformNotification.AndroidSpecificProperties _androidProperties = new CrossPlatformNotification.AndroidSpecificProperties();
            _androidProperties.ContentTitle = "content title";
            _androidProperties.TickerText   = "ticker ticks over here";
            _androidProperties.LargeIcon    = "NativePlugins.png";             //Keep the files in Assets/PluginResources/Android or Common folder.

            CrossPlatformNotification _notification = new CrossPlatformNotification();

            _notification.AlertBody         = "alert body";                     //On Android, this is considered as ContentText
            _notification.FireDate          = System.DateTime.Now.AddSeconds(_fireAfterSec);
            _notification.RepeatInterval    = _repeatInterval;
            _notification.SoundName         = "Notification.mp3";                     //Keep the files in Assets/PluginResources/Android or iOS or Common folder.
            _notification.UserInfo          = _userInfo;
            _notification.iOSProperties     = _iosProperties;
            _notification.AndroidProperties = _androidProperties;

            return(_notification);
        }
Ejemplo n.º 3
0
 private void TryFixInterval()
 {
     if (isFortnight)
     {
         if (this.repeatInterval != eNotificationRepeatInterval.NONE)
         {
             Debug.LogWarning(
                 $"Repeat interval for FORTNIGHT repetition must be NONE, but it's <{this.repeatInterval}>");
             this.repeatInterval = eNotificationRepeatInterval.NONE;
         }
     }
 }
Ejemplo n.º 4
0
        public void SetNotification(DateTime fireDate, eNotificationRepeatInterval repeatInterval, string parentGroupId,
                                    bool isFortnight, string title, string message = null)
        {
            this.isFortnight    = isFortnight;
            this.fireDate       = fireDate;
            this.repeatInterval = repeatInterval;
            this.parentGroupId  = parentGroupId;
            this.title          = title;
            this.message        = message;

            SetNotification();
        }
Ejemplo n.º 5
0
        public void ChangeRepeatInterval(eNotificationRepeatInterval repeatInterval, bool isFortnight = false)
        {
            if (this.repeatInterval == repeatInterval)
            {
                Debug.LogWarning("Trying to change notification with a same repeat interval! Return.");
                return;
            }

            this.repeatInterval = repeatInterval;
            TryFixInterval();

            RemoveAllNotifications();
            SetNotification();

            OnDataUpdate?.Invoke();
        }
Ejemplo n.º 6
0
        public override void Reset()
        {
            // Setup properties
            alertBody        = null;
            fireAfterMinutes = 1;
            repeatInterval   = eNotificationRepeatInterval.NONE;
            soundName        = null;
            alertAction      = null;
            hasAction        = false;
            badgeCount       = 0;
            launchImage      = null;
            contentTitle     = null;
            tickerText       = null;
            tag       = null;
            largeIcon = null;

            // Results properties
            notificationID = new FsmString {
                UseVariable = true
            };
        }
        public static CalendarUnit ConvertToCalendarUnit(eNotificationRepeatInterval _repeatInterval)
        {
            switch (_repeatInterval)
            {
            case eNotificationRepeatInterval.MINUTE:
                return(CalendarUnit.Minute);

            case eNotificationRepeatInterval.DAY:
                return(CalendarUnit.Day);

            case eNotificationRepeatInterval.WEEK:
                return(CalendarUnit.Week);

            case eNotificationRepeatInterval.MONTH:
                return(CalendarUnit.Month);

            case eNotificationRepeatInterval.YEAR:
                return(CalendarUnit.Year);

            default:
                return(0);
            }
        }
Ejemplo n.º 8
0
    private CrossPlatformNotification CreateNotification(long _fireAfterSec, eNotificationRepeatInterval _repeatInterval)
    {
        // User info
        IDictionary _userInfo = new Dictionary <string, string>();

        _userInfo["data"] = "add what is required";

        CrossPlatformNotification.iOSSpecificProperties _iosProperties = new CrossPlatformNotification.iOSSpecificProperties();
        _iosProperties.HasAction   = true;
        _iosProperties.AlertAction = GMS.appName;

        CrossPlatformNotification.AndroidSpecificProperties _androidProperties = new CrossPlatformNotification.AndroidSpecificProperties();
        _androidProperties.ContentTitle = GMS.amigoData.nombre;
        _androidProperties.TickerText   = GMS.appName;
        _androidProperties.CustomSound  = "Notification.mp3";         //Keep the files in Assets/StreamingAssets/VoxelBusters/NativePlugins/Android folder.
        //_androidProperties.LargeIcon	= "NativePlugins.png"; //Keep the files in Assets/StreamingAssets/VoxelBusters/NativePlugins/Android folder.
        if (GMS.checkImageExists(GMS.amigoData.foto))
        {
            _androidProperties.LargeIcon = Application.persistentDataPath + "/" + GMS.amigoData.foto;
        }
        else
        {
            _androidProperties.LargeIcon = "default.jpg";
        }

        CrossPlatformNotification _notification = new CrossPlatformNotification();

        _notification.AlertBody         = MgsTextNotif;                 //On Android, this is considered as ContentText
        _notification.FireDate          = System.DateTime.Now.AddSeconds(_fireAfterSec);
        _notification.RepeatInterval    = _repeatInterval;
        _notification.UserInfo          = _userInfo;
        _notification.iOSProperties     = _iosProperties;
        _notification.AndroidProperties = _androidProperties;

        return(_notification);
    }
Ejemplo n.º 9
0
        private void RegisterNotification(long startInSecs, eNotificationRepeatInterval repeatInterval)
        {
            // CrossPlatformNotification class it too huge to save using GameSave asset, but we need just some short data
            CrossPlatformNotification notification =
                ReminderManager.Instance.CreateNotification(title, startInSecs, repeatInterval);

            // cache notification
            string id = ReminderManager.Instance.ScheduleLocalNotification(notification);

            if (!notificationsDict.ContainsKey(id) && !idArray.Contains(id))
            {
                notificationsDict.Add(id,
                                      new NotificationInfo {
                    id = id, fireDate = fireDate, repeatInterval = repeatInterval
                });
                idArray.Add(id);
                Debug.Log(
                    $"Registering notification with title: {title}, parent group id: {parentGroupId}, reminder start fire date: {fireDate} and actual fire date: {DateTime.Now.AddSeconds(startInSecs)}, interval: {repeatInterval}, and id: {id}");
            }
            else
            {
                throw new Exception($"Notification with id <{id}> already registered and added to dict");
            }
        }
Ejemplo n.º 10
0
	private CrossPlatformNotification CreateNotification (long _fireAfterSec, eNotificationRepeatInterval _repeatInterval)
	{
		// User info
		IDictionary _userInfo			= new Dictionary<string, string>();
		_userInfo["data"]				= "add what is required";
		
		CrossPlatformNotification.iOSSpecificProperties _iosProperties			= new CrossPlatformNotification.iOSSpecificProperties();
		_iosProperties.HasAction		= true;
		_iosProperties.AlertAction		= GMS.appName;
		
		CrossPlatformNotification.AndroidSpecificProperties _androidProperties	= new CrossPlatformNotification.AndroidSpecificProperties();
		_androidProperties.ContentTitle	= GMS.amigoData.nombre;
		_androidProperties.TickerText	= GMS.appName;
		_androidProperties.CustomSound	= "Notification.mp3"; //Keep the files in Assets/StreamingAssets/VoxelBusters/NativePlugins/Android folder.
		//_androidProperties.LargeIcon	= "NativePlugins.png"; //Keep the files in Assets/StreamingAssets/VoxelBusters/NativePlugins/Android folder.
		if (GMS.checkImageExists (GMS.amigoData.foto)) {
			_androidProperties.LargeIcon = Application.persistentDataPath + "/" + GMS.amigoData.foto;
		} else {
			_androidProperties.LargeIcon	= "default.jpg";
		}
		
		CrossPlatformNotification _notification	= new CrossPlatformNotification();
		_notification.AlertBody			= MgsTextNotif; //On Android, this is considered as ContentText
		_notification.FireDate			= System.DateTime.Now.AddSeconds(_fireAfterSec);
		_notification.RepeatInterval	= _repeatInterval;
		_notification.UserInfo			= _userInfo;
		_notification.iOSProperties		= _iosProperties;
		_notification.AndroidProperties	= _androidProperties;
		
		return _notification;
	}
        private void MonitorScheduledLocalNotifications()
        {
            if (ScheduledLocalNotifications == null || ScheduledLocalNotifications.Count == 0)
            {
                return;
            }

            int _scheduledNotificationsCount = ScheduledLocalNotifications.Count;

            System.DateTime _now = System.DateTime.Now;

            for (int _iter = 0; _iter < _scheduledNotificationsCount; _iter++)
            {
                CrossPlatformNotification _scheduledNotification = ScheduledLocalNotifications[_iter];
                int _secondsSinceNow = (int)(_now - _scheduledNotification.FireDate).TotalSeconds;

                // Can fire event
                if (_secondsSinceNow > 0)
                {
                    OnReceivingLocalNotification(_scheduledNotification);

                    // Handle notification based on its repeat interval
                    eNotificationRepeatInterval _repeatInterval = _scheduledNotification.RepeatInterval;

                    switch (_repeatInterval)
                    {
                    case eNotificationRepeatInterval.NONE:
                        // Remove the notification from scheduled list, as its not repeatable
                        ScheduledLocalNotifications.RemoveAt(_iter);
                        _scheduledNotificationsCount--;
                        _iter--;
                        break;

                    case eNotificationRepeatInterval.MINUTE:
                        _scheduledNotification.FireDate = _scheduledNotification.FireDate.AddMinutes(1);
                        break;

                    case eNotificationRepeatInterval.HOUR:
                        _scheduledNotification.FireDate = _scheduledNotification.FireDate.AddHours(1);
                        break;

                    case eNotificationRepeatInterval.DAY:
                        _scheduledNotification.FireDate = _scheduledNotification.FireDate.AddDays(1);
                        break;

                    case eNotificationRepeatInterval.WEEK:
                        _scheduledNotification.FireDate = _scheduledNotification.FireDate.AddDays(7);
                        break;

                    case eNotificationRepeatInterval.MONTH:
                        _scheduledNotification.FireDate = _scheduledNotification.FireDate.AddMonths(1);
                        break;

                    case eNotificationRepeatInterval.YEAR:
                        _scheduledNotification.FireDate = _scheduledNotification.FireDate.AddYears(1);
                        break;

                    default:
                        Console.LogError(Constants.kDebugTag, "[RS] Unhandled notification interval=" + _repeatInterval);
                        break;
                    }
                }
            }
        }
		private CrossPlatformNotification CreateNotification (long _fireAfterSec, eNotificationRepeatInterval _repeatInterval)
		{
			// User info
			IDictionary _userInfo			= new Dictionary<string, string>();
			_userInfo["data"]				= "add what is required";
			
			CrossPlatformNotification.iOSSpecificProperties _iosProperties			= new CrossPlatformNotification.iOSSpecificProperties();
			_iosProperties.HasAction		= true;
			_iosProperties.AlertAction		= "alert action";
			
			CrossPlatformNotification.AndroidSpecificProperties _androidProperties	= new CrossPlatformNotification.AndroidSpecificProperties();
			_androidProperties.ContentTitle	= "content title";
			_androidProperties.TickerText	= "ticker ticks over here";
			_androidProperties.CustomSound	= "Notification.mp3"; //Keep the files in Assets/StreamingAssets/VoxelBusters/NativePlugins/Android folder.
			_androidProperties.LargeIcon	= "NativePlugins.png"; //Keep the files in Assets/StreamingAssets/VoxelBusters/NativePlugins/Android folder.
			
			CrossPlatformNotification _notification	= new CrossPlatformNotification();
			_notification.AlertBody			= "alert body"; //On Android, this is considered as ContentText
			_notification.FireDate			= System.DateTime.Now.AddSeconds(_fireAfterSec);
			_notification.RepeatInterval	= _repeatInterval;
			_notification.UserInfo			= _userInfo;
			_notification.iOSProperties		= _iosProperties;
			_notification.AndroidProperties	= _androidProperties;

			return _notification;
		}
		public static CalendarUnit ConvertToCalendarUnit (eNotificationRepeatInterval _repeatInterval)
		{
			switch (_repeatInterval)
			{
			case eNotificationRepeatInterval.MINUTE:
				return CalendarUnit.Minute;
				
			case eNotificationRepeatInterval.DAY:
				return CalendarUnit.Day;
				
			case eNotificationRepeatInterval.WEEK:
				return CalendarUnit.Week;
				
			case eNotificationRepeatInterval.MONTH:
				return CalendarUnit.Month;
				
			case eNotificationRepeatInterval.YEAR:
				return CalendarUnit.Year;
				
			default:
				return 0;
			}
		}
Ejemplo n.º 14
0
        private CrossPlatformNotification CreateNotification(System.DateTime _date, string content, eNotificationRepeatInterval _repeatInterval)
        {
            // User info
            IDictionary _userInfo = new Dictionary <string, string>();

            _userInfo["data"] = "custom data";

            CrossPlatformNotification.iOSSpecificProperties _iosProperties = new CrossPlatformNotification.iOSSpecificProperties();
            _iosProperties.HasAction   = true;
            _iosProperties.AlertAction = content;

            CrossPlatformNotification.AndroidSpecificProperties _androidProperties = new CrossPlatformNotification.AndroidSpecificProperties();
            _androidProperties.ContentTitle = Application.productName; // "银之守墓人";
            _androidProperties.TickerText   = content;
            _androidProperties.LargeIcon    = "hualing.png";           //Keep the files in Assets/PluginResources/Android or Common folder.

            CrossPlatformNotification _notification = new CrossPlatformNotification();

            _notification.AlertBody         = content; //On Android, this is considered as ContentText
            _notification.FireDate          = _date;
            _notification.RepeatInterval    = _repeatInterval;
            _notification.SoundName         = ""; //Keep the files in Assets/PluginResources/Android or iOS or Common folder.
            _notification.UserInfo          = _userInfo;
            _notification.iOSProperties     = _iosProperties;
            _notification.AndroidProperties = _androidProperties;

            return(_notification);
        }
Ejemplo n.º 15
0
 public string AddNotification(long _fireAfterSec, string content, eNotificationRepeatInterval _repeatInterval)
 {
     return(ScheduleLocalNotification(CreateNotification(System.DateTime.Now.AddSeconds(_fireAfterSec), content, _repeatInterval)));
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Important to call to save Reminder changes and write data.
        /// </summary>
        public void SetupReminder()
        {
            RemoveAllNotifications();

            NotificationData data;

            eNotificationRepeatInterval notificationRepeatInterval = eNotificationRepeatInterval.NONE;

            // covert to VoxelBuster plugin data format
            switch (this.repeatInterval)
            {
            case RepeatInterval.ONCE:
                notificationRepeatInterval = eNotificationRepeatInterval.NONE;
                break;

            case RepeatInterval.DAY:
                notificationRepeatInterval = eNotificationRepeatInterval.DAY;
                break;

            case RepeatInterval.WEEK:
                notificationRepeatInterval = eNotificationRepeatInterval.WEEK;
                break;

            case RepeatInterval.FORTNIGHT:
                notificationRepeatInterval = eNotificationRepeatInterval.NONE;
                break;

            case RepeatInterval.MONTH:
                notificationRepeatInterval = eNotificationRepeatInterval.MONTH;
                break;
            }

            // when user set multiple days of week, need to add notification for each of the day
            if (daysOfWeek != null && daysOfWeek.Length > 1)
            {
                int fireDateIndex = (int)fireDate.DayOfWeek;

                for (int i = 0; i < daysOfWeek.Length; i++)
                {
                    data = new NotificationData();
                    int index = (int)daysOfWeek[i];

                    DateTime notificationFireDate = fireDate.AddDays(index - fireDateIndex);

                    data.SetNotification(notificationFireDate, notificationRepeatInterval, id,
                                         this.repeatInterval == RepeatInterval.FORTNIGHT, title, message);

                    // cache it
                    notifications.Add(data);
                }
            }
            //  set new notification - in most cases use simple logic
            else
            {
                data = new NotificationData();
                data.SetNotification(fireDate, notificationRepeatInterval, id,
                                     this.repeatInterval == RepeatInterval.FORTNIGHT, title, message);

                // cache it
                notifications.Add(data);
            }

            OnDataUpdate?.Invoke(this);
        }