Search Unity

mobile notification not being rescheduled after losing->regaining->relosing focus

Discussion in 'Android' started by ADNCG, Mar 28, 2022.

  1. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    Using unity's mobile notifications package and the samples with it.

    If I schedule a notification, minimize the app, the notification works fine.
    If I schedule a notification, minimize the app, re-enter the app, minimize it again, the notification isn't fired.

    The operating mode from the GameNotificationsManager is set to QueueClearAndReschedule, so the above scenario should be covered, in theory. When scheduling a notification via GameNotificationsManager.ScheduleNotification(), I am setting .Reschedule to true on the returned PendingNotification instance.

    Any idea?
     
  2. dskillsaw

    dskillsaw

    Joined:
    Apr 26, 2012
    Posts:
    13
    I was just banging my head against a weird behavior where every time my application loses and re-gains focus, the DeliveryTime of my notification seems to advance 7 hours into the future.

    I'm testing by looping over GameNotificationsManager.PendingNotifications, and logging
    pendingNotification.Notification.DeliveryTime

    I may be doing something wrong, but it almost seems like time zone shenanigans? I can't track down where in my code, or the mobile notification package, the 7 hours could be getting introduced.
     
    ADNCG likes this.
  3. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    I'm on vacation at the moment and cannot confirm, but it seems like a plausible explanation to what I've been experiencing.

    I'll investigate and confirm/post fix next monday. Thank you for the pointer!
     
  4. dskillsaw

    dskillsaw

    Joined:
    Apr 26, 2012
    Posts:
    13
    sounds good! it'll be interesting if the same thing is happening to you. I also cross posted this thread here in case someone has ideas.
     
  5. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    128
    Hello,

    I am seeing a similar issue now too. Notifications on ios seem to have the delivery time changed immediately after it being set (in my case, -10 hours, which makes sense because I'm +10 GMT). This usually results in the notification immediately being dequed because it is "expired".

    Just had a quick look through the ios notification code, and there are some ToUTC and ToLocal scattered about, so something is going wrong somewhere. Time permitting, I'll try track down the issue.

    Thanks.
     
  6. dskillsaw

    dskillsaw

    Joined:
    Apr 26, 2012
    Posts:
    13
    Thx for confirming you're seeing it too, Chris. Hopefully if you're not able to spot a fix, Unity folks will chime in soon with help.
     
  7. MetalCodeGames

    MetalCodeGames

    Joined:
    Mar 4, 2019
    Posts:
    5
    I ran into the same issue when I updated from Unity 2020.17 to 2020.3.31f. Not sure exactly what is causing the error, but here's a temp workaround I wrote for iOS notification schedule. The idea was just to add the difference if the timezone is set wrong which results in the correct actual time scheduled on iOS.
    Code (CSharp):
    1. notification.DeliveryTime = deliveryTime;
    2.             if (notification.DeliveryTime != deliveryTime)
    3.             {
    4.                 TimeSpan tempDiff = deliveryTime - notification.DeliveryTime.Value;
    5.                 DateTime deliverTimePatched = deliveryTime.Add(tempDiff);
    6.                 notification.DeliveryTime = deliverTimePatched;
    7.             }