Skip to content

Commit d81ddea

Browse files
Merge pull request #3 from CoderGamester/develop
Release 0.1.3
2 parents 4bb7cf1 + 5560c61 commit d81ddea

13 files changed

+97
-212
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.1.3] - 2020-08-03
8+
9+
**Fixed**:
10+
- Fixed saved notifications serialization on iOS
11+
712
## [0.1.2] - 2020-07-29
813

914
**Fixed**:

Runtime/GameLovers.NotificationService.asmdef

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"includePlatforms": [],
88
"excludePlatforms": [],
99
"allowUnsafeCode": false,
10-
"overrideReferences": false,
10+
"overrideReferences": true,
1111
"precompiledReferences": [],
1212
"autoReferenced": true,
1313
"defineConstraints": [],

Runtime/GameNotificationsMonoBehaviour.cs

+19-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Linq;
54
using UnityEngine;
65

@@ -67,9 +66,8 @@ public enum OperatingMode
6766
/// </summary>
6867
public sealed class GameNotificationsMonoBehaviour : MonoBehaviour
6968
{
70-
// Default filename for notifications serializer
71-
private const string _DEFAULT_FILENAME = "notifications.bin";
72-
69+
70+
7371
// Minimum amount of time that a notification should be into the future before it's queued when we background.
7472
private static readonly TimeSpan _minimumNotificationTime = new TimeSpan(0, 0, 2);
7573

@@ -87,23 +85,22 @@ public sealed class GameNotificationsMonoBehaviour : MonoBehaviour
8785
/// <summary>
8886
/// Event fired when a scheduled local notification is delivered while the app is in the foreground.
8987
/// </summary>
90-
public Action<PendingNotification> LocalNotificationDelivered;
88+
public Action<PendingNotification> OnLocalNotificationDelivered;
9189

9290
/// <summary>
9391
/// Event fired when a queued local notification is cancelled because the application is in the foreground
9492
/// when it was meant to be displayed.
9593
/// </summary>
9694
/// <seealso cref="OperatingMode.Queue"/>
97-
public Action<PendingNotification> LocalNotificationExpired;
95+
public Action<PendingNotification> OnLocalNotificationExpired;
9896

9997
private IGameNotificationsPlatform _platform;
100-
private IPendingNotificationsSerializer _serializer;
10198
private bool _inForeground = true;
10299

103100
/// <summary>
104101
/// Gets a collection of notifications that are scheduled or queued.
105102
/// </summary>
106-
public List<PendingNotification> PendingNotifications { get; private set; }
103+
public List<PendingNotification> PendingNotifications { get; private set; } = new List<PendingNotification>();
107104

108105
/// <summary>
109106
/// Gets whether this manager has been initialized.
@@ -147,7 +144,7 @@ private void Update()
147144
if (time != null && time < DateTime.Now)
148145
{
149146
PendingNotifications.RemoveAt(i);
150-
LocalNotificationExpired?.Invoke(queuedNotification);
147+
OnLocalNotificationExpired?.Invoke(queuedNotification);
151148
}
152149
}
153150
}
@@ -255,7 +252,7 @@ private void OnApplicationFocus(bool hasFocus)
255252
}
256253

257254
// Calculate notifications to save
258-
var notificationsToSave = new List<PendingNotification>(PendingNotifications.Count);
255+
var notificationsToSave = new List<SerializableNotification>(PendingNotifications.Count);
259256
foreach (var pendingNotification in PendingNotifications)
260257
{
261258
// If we're in clear mode, add nothing unless we're in rescheduling mode
@@ -273,21 +270,21 @@ private void OnApplicationFocus(bool hasFocus)
273270
pendingNotification.Notification.Scheduled &&
274271
pendingNotification.Notification.DeliveryTime.HasValue)
275272
{
276-
notificationsToSave.Add(pendingNotification);
273+
notificationsToSave.Add(pendingNotification.AsSerializableNotification());
277274
}
278275
}
279276
else
280277
{
281278
// In non-clear mode, just add all scheduled notifications
282279
if (pendingNotification.Notification.Scheduled)
283280
{
284-
notificationsToSave.Add(pendingNotification);
281+
notificationsToSave.Add(pendingNotification.AsSerializableNotification());
285282
}
286283
}
287284
}
288285

289286
// Save to disk
290-
_serializer.Serialize(notificationsToSave);
287+
PlayerPrefs.SetString("notifications", JsonUtility.ToJson(notificationsToSave));
291288
}
292289

293290
/// <summary>
@@ -330,15 +327,8 @@ public void Initialize(params GameNotificationChannel[] channels)
330327
return;
331328
}
332329

333-
PendingNotifications = new List<PendingNotification>();
334330
_platform.NotificationReceived += OnNotificationReceived;
335331

336-
// Check serializer
337-
if (_serializer == null)
338-
{
339-
_serializer = new DefaultSerializer(Path.Combine(Application.persistentDataPath, _DEFAULT_FILENAME));
340-
}
341-
342332
OnForegrounding();
343333
}
344334

@@ -488,7 +478,7 @@ private void OnNotificationReceived(IGameNotification deliveredNotification)
488478

489479
if (deliveredIndex >= 0)
490480
{
491-
LocalNotificationDelivered?.Invoke(PendingNotifications[deliveredIndex]);
481+
OnLocalNotificationDelivered?.Invoke(PendingNotifications[deliveredIndex]);
492482
PendingNotifications.RemoveAt(deliveredIndex);
493483
}
494484
}
@@ -500,7 +490,7 @@ private void OnForegrounding()
500490
_platform.OnForeground();
501491

502492
// Deserialize saved items
503-
var loaded = _serializer?.Deserialize(_platform);
493+
var notifications = JsonUtility.FromJson<List<SerializableNotification>>(PlayerPrefs.GetString("notifications"));
504494

505495
// Foregrounding
506496
if ((Mode & OperatingMode.ClearOnForegrounding) == OperatingMode.ClearOnForegrounding)
@@ -509,17 +499,18 @@ private void OnForegrounding()
509499
_platform.CancelAllScheduledNotifications();
510500

511501
// Only reschedule in reschedule mode, and if we loaded any items
512-
if (loaded == null || (Mode & OperatingMode.RescheduleAfterClearing) != OperatingMode.RescheduleAfterClearing)
502+
if (notifications == null || (Mode & OperatingMode.RescheduleAfterClearing) != OperatingMode.RescheduleAfterClearing)
513503
{
514504
return;
515505
}
516506

517507
// Reschedule notifications from deserialization
518-
foreach (var savedNotification in loaded)
508+
foreach (var savedNotification in notifications)
519509
{
520510
if (savedNotification.DeliveryTime > DateTime.Now)
521511
{
522-
var pendingNotification = ScheduleNotification(savedNotification);
512+
var pendingNotification = ScheduleNotification(savedNotification.AsGameNotification(_platform));
513+
523514
pendingNotification.Reschedule = true;
524515
}
525516
}
@@ -528,16 +519,16 @@ private void OnForegrounding()
528519
{
529520
// Just create PendingNotification wrappers for all deserialized items.
530521
// We're not rescheduling them because they were not cleared
531-
if (loaded == null)
522+
if (notifications == null)
532523
{
533524
return;
534525
}
535526

536-
foreach (var savedNotification in loaded)
527+
foreach (var savedNotification in notifications)
537528
{
538529
if (savedNotification.DeliveryTime > DateTime.Now)
539530
{
540-
PendingNotifications.Add(new PendingNotification(savedNotification));
531+
PendingNotifications.Add(new PendingNotification(savedNotification.AsGameNotification(_platform)));
541532
}
542533
}
543534
}

Runtime/IGameNotification.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public interface IGameNotification
4141
string Subtitle { get; set; }
4242

4343
/// <summary>
44-
/// Gets or sets group to which this notification belongs.
44+
/// Gets or sets channel to which this notification belongs.
4545
/// </summary>
46-
/// <value>A platform specific string identifier for the notification's group.</value>
47-
string Group { get; set; }
46+
/// <value>A platform specific string identifier for the notification's channel.</value>
47+
string Channel { get; set; }
4848

4949
/// <summary>
5050
/// Gets or sets the badge number for this notification. No badge number will be shown if null.

Runtime/Internal/DefaultSerializer.cs

-140
This file was deleted.

Runtime/Internal/DefaultSerializer.cs.meta

-3
This file was deleted.

Runtime/Internal/IPendingNotificationsSerializer.cs

-26
This file was deleted.

Runtime/Internal/IPendingNotificationsSerializer.cs.meta

-3
This file was deleted.

0 commit comments

Comments
 (0)