Search Unity

Clearing local notifications not working

Discussion in 'iOS and tvOS' started by breban1, Mar 22, 2017.

  1. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    194
    I'm attempting to get local notifications working on iOS and having a heck of a time, any help would be appreciated.

    I first call:
    UnityEngine.iOS.NotificationServices.RegisterForNotifications(
    UnityEngine.iOS.NotificationType.Alert |
    UnityEngine.iOS.NotificationType.Sound);

    Then:
    UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification();
    localNotification.alertAction = notificationParams.Title;
    localNotification.alertBody = notificationParams.Message;
    localNotification.fireDate = DateTime.Now.AddSeconds(notificationParams.Delay.TotalSeconds);
    localNotification.userInfo = new Dictionary<int, int>(1);
    localNotification.userInfo.Add(notificationParams.Id, notificationParams.Id);
    UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(localNotification);

    To try to clear the notification from the tray:
    UnityEngine.iOS.NotificationServices.ClearLocalNotifications();

    I've also tried:
    loop id:
    UnityEngine.iOS.NotificationServices.CancelLocalNotification(id)

    I get the local notifications to fire, I just can't clear them so they stay in the "Tray" or whatever it is called, any ideas?

    TIA
     
  2. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    When I call this the received array gets cleared.
     
  3. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    194
    Calling this function clears the notification from the iOS tray for you? Meaning the Home Screen on iOS, I'm not sure if it's actually called the "Tray".
     
  4. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I didn't understand that's what you meant.

    No, the 'tray' is not cleared. But the app doesn't seem to know about the notifications in the 'tray' as far as I can see. Once you touch a notification it is cleared from the 'tray' and then is added to the received array.
     
  5. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    194
    Gotcha, I guess they'll just stay there until the user dismisses them. I wasn't sure if this was normal behavior.

    Thanks for the info!