Search Unity

local notifications, cancelling a specific notificaton

Discussion in 'iOS and tvOS' started by hakankaraduman, Feb 18, 2017.

  1. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    Hi,

    I use UnityEngine.IOS.NotificationServices class and I need to find a specific notification and cancel it, scripting api/manual page for CancelNotification is empty and I also can't find any best practices guide to use these class in my game.

    Can anyone with experience help me? Thanks
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    You should use the NotificationServices.localNotifications property.

    This gives you back an array of local notifications.

    Find the relevant notification (represented by the LocalNotification class) and pass that to the CancelLocalNotification method.
     
  3. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    thanks for the reply,

    but how do I specifically schedule and cancel a notification? Let's say I want to schedule two notifications, one for a weapon, one for an item. and then I need to find from this localNotifications array which one is for weapon, so that I can cancel it.
     
  4. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Either store the references yourself or iterate the scheduled notifications array and query each one for some information that tells you which is which, e.g. the message, or the fireDate, or the userInfo.
     
  5. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    Hi,

    I tried again and it does not register any info to the userInfo dictionary. Contains() method returns false and it also shows that the count property of the userinfo dictionary is zero. But it registers alertBody and alertAction fields.

    Do you think this dictionary behavior could be a bug?
     
  6. Lucasito

    Lucasito

    Joined:
    Mar 22, 2013
    Posts:
    80