Esempio n. 1
0
        /// <inheritdoc />
        public IList <IGameNotification> Deserialize(IGameNotificationsPlatform platform)
        {
            if (!File.Exists(filename))
            {
                return(null);
            }

            using (var file = new FileStream(filename, FileMode.Open))
            {
                using (var reader = new BinaryReader(file))
                {
                    // Version
                    reader.ReadByte();

                    // Length
                    int numElements = reader.ReadInt32();

                    var result = new List <IGameNotification>(numElements);
                    for (var i = 0; i < numElements; ++i)
                    {
                        IGameNotification notification = platform.CreateNotification();
                        bool hasValue;

                        // ID
                        hasValue = reader.ReadBoolean();
                        if (hasValue)
                        {
                            notification.Id = reader.ReadInt32();
                        }

                        // Title
                        notification.Title = reader.ReadString();

                        // Body
                        notification.Body = reader.ReadString();

                        // Body
                        notification.Subtitle = reader.ReadString();

                        // Group
                        notification.Group = reader.ReadString();

                        // Badge
                        hasValue = reader.ReadBoolean();
                        if (hasValue)
                        {
                            notification.BadgeNumber = reader.ReadInt32();
                        }

                        // Time
                        notification.DeliveryTime = new DateTime(reader.ReadInt64(), DateTimeKind.Local);

                        result.Add(notification);
                    }

                    return(result);
                }
            }
        }
        public static IGameNotification AsGameNotification(this SerializableNotification serializableNotification,
                                                           IGameNotificationsPlatform platform)
        {
            var notification = platform.CreateNotification();

            notification.Id           = serializableNotification.Id;
            notification.Title        = serializableNotification.Title;
            notification.Body         = serializableNotification.Body;
            notification.Subtitle     = serializableNotification.Subtitle;
            notification.Channel      = serializableNotification.Channel;
            notification.BadgeNumber  = serializableNotification.BadgeNumber;
            notification.DeliveryTime = serializableNotification.DeliveryTime;

            return(notification);
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize the notifications manager.
        /// </summary>
        /// <param name="channels">An optional collection of channels to register, for Android</param>
        /// <exception cref="InvalidOperationException"><see cref="Initialize"/> has already been called.</exception>
        public void Initialize(params GameNotificationChannel[] channels)
        {
            if (Initialized)
            {
                throw new InvalidOperationException("NotificationsManager already initialized.");
            }

            Initialized = true;

#if UNITY_ANDROID
            _platform = new AndroidNotificationsPlatform();

            // Register the notification channels
            var doneDefault = false;
            foreach (var notificationChannel in channels)
            {
                var platform = _platform as AndroidNotificationsPlatform;

                if (!doneDefault)
                {
                    doneDefault = true;
                    platform.DefaultChannelId = notificationChannel.Id;
                }

                platform.RegisterChannel(notificationChannel);
            }
#elif UNITY_IOS
            _platform = new iOSNotificationsPlatform();
#endif

            if (_platform == null)
            {
                return;
            }

            _platform.NotificationReceived += OnNotificationReceived;

            OnForegrounding();
        }