Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

iOS Local Notification Not Being Created

Discussion in 'iOS and tvOS' started by UltraAccel, May 26, 2015.

  1. UltraAccel

    UltraAccel

    Joined:
    Oct 14, 2014
    Posts:
    4
    I'm attempting to set a Local Notification in my game, but after being initiated, it seems like none of the variable's attributes can be altered.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.iOS;
    3. using System;
    4. using System.Collections;
    5.  
    6. public class notification_controller : MonoBehaviour {
    7.  
    8.     public void CreateNotification(){
    9.         UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification();
    10.         notif.fireDate = System.DateTime.Now.AddSeconds(10);
    11.         notif.applicationIconBadgeNumber = 1;
    12.         notif.hasAction = true;
    13.         notif.alertBody = "Text here";
    14.         Debug.Log (notif.fireDate);
    15.         UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif);
    16.         Debug.Log(UnityEngine.iOS.NotificationServices.scheduledLocalNotifications);
    17.     }
    18. }

    When the code is run, the log for fireDate outputs 1/1/2001 (not today) and the scheduledLocalNotifications array is empty. Is there a problem with my code or is this a problem with the notifications system? Thanks.
     
  2. ImaginaryChris

    ImaginaryChris

    Joined:
    Nov 25, 2013
    Posts:
    20
    I'm getting something similar, my fireDate reads as 7 hours for from when I set it. Like the timezone is being offset by my timezone from UTC.
     
  3. UltraAccel

    UltraAccel

    Joined:
    Oct 14, 2014
    Posts:
    4
    I submitted a bug report to Unity to see if it's a recurring glitch. Hopefully they'll look into it.
     
  4. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Have you called registered the types of notifications?

    Code (CSharp):
    1. NotificationServices.RegisterForLocalNotificationTypes(LocalNotificationType.Alert|LocalNotificationType.Badge);
    The fire date should be fine. I just think that the value returned from the property is wrong but it's correct internally. That's what I noticed anyway. I have local notifications working as expected in my apps.
     
  5. ImaginaryChris

    ImaginaryChris

    Joined:
    Nov 25, 2013
    Posts:
    20
    I'm using Unity 5, they have removed the RegisterForLocalNotificationTypes method and replaced it with just a generic register method. It seems to work fine for push notifications, just the local ones do not show up.
     
  6. UltraAccel

    UltraAccel

    Joined:
    Oct 14, 2014
    Posts:
    4
    I have local notifications registered in a Start method as you suggested. I'll have to see if the notification works on my phone even though it appears to be unaffected in the code. Thanks.
     
  7. redstonegames

    redstonegames

    Joined:
    Sep 19, 2015
    Posts:
    11
    I'm facing the same issue here. Notifications are being scheduled 3 hours from the assigned fireDate. Do somebody have a solution to this problem?
     
  8. redstonegames

    redstonegames

    Joined:
    Sep 19, 2015
    Posts:
    11
    Did you find a solution?