Skip to content

Commit 14ac05f

Browse files
authored
Merge pull request #243 from Unity-Technologies/ios-userinfo-checks
Fix exception on missing UTC flag
2 parents ed98519 + 28e4486 commit 14ac05f

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

com.unity.mobile.notifications/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ All notable changes to this package will be documented in this file.
66

77
### Fixes:
88
- [Android] - No longer use DeniedAndDontAskAgain permission response, only Denied.
9-
- [iOS] - Fix occasional crash when registering for push notifications.
9+
- [iOS] - [issue 205](https://github.com/Unity-Technologies/com.unity.mobile.notifications/issues/205) Fix occasional crash when registering for push notifications.
10+
- [iOS] - [issue 242](https://github.com/Unity-Technologies/com.unity.mobile.notifications/issues/242) Fix exception when OriginalUtc key is missing in data (for example notification was scheduled using older package version).
1011

1112
## [2.1.0] - 2022-09-23
1213

com.unity.mobile.notifications/Runtime/iOS/iOSNotification.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,19 @@ public iOSNotificationTrigger Trigger
389389
UtcTime = true,
390390
Repeats = data.trigger.calendar.repeats != 0
391391
};
392-
if (userInfo != null && userInfo["OriginalUtc"] == "0")
393-
trigger = trigger.ToLocal();
392+
if (userInfo != null)
393+
{
394+
string utc;
395+
if (userInfo.TryGetValue("OriginalUtc", out utc))
396+
{
397+
if (utc == "0")
398+
trigger = trigger.ToLocal();
399+
}
400+
else
401+
trigger.UtcTime = false;
402+
}
403+
else
404+
trigger.UtcTime = false;
394405
return trigger;
395406
}
396407
case iOSNotificationTriggerType.Location:

com.unity.mobile.notifications/Tests/Runtime/iOS/iOSNotificationTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,26 @@ public void iOSNotification_CalendarTrigger_ReturnsSameKindDateTime()
388388
Assert.AreEqual(trigger2.Minute, retTrigger.Minute);
389389
Assert.AreEqual(trigger2.UtcTime, retTrigger.UtcTime);
390390
}
391+
392+
[Test]
393+
public void iOSNotificationCalendarTrigger_HandlesMissingUtcField()
394+
{
395+
var original = new iOSNotificationCalendarTrigger()
396+
{
397+
Day = 5,
398+
};
399+
400+
var notification = new iOSNotification()
401+
{
402+
Trigger = original,
403+
};
404+
405+
// clear UserInfo, where UTC flag is stored
406+
notification.UserInfo.Clear();
407+
408+
Assert.AreEqual(iOSNotificationTriggerType.Calendar, notification.Trigger.Type);
409+
var result = (iOSNotificationCalendarTrigger)notification.Trigger;
410+
Assert.AreEqual(5, result.Day);
411+
Assert.IsFalse(result.UtcTime);
412+
}
391413
}

0 commit comments

Comments
 (0)