-1

I cannot find a proper tutorial on sending scheduled local notifications

I came up with this but below code is not working

void Start()

    {
        LocalNotification notif = new LocalNotification();

        notif.fireDate          = System.DateTime.Now.AddSeconds(5f);

        notif.alertBody         = "Hey";    

        NotificationServices.ScheduleLocalNotification(notif);

     }

Please help me with this

Sport
  • 8,570
  • 6
  • 46
  • 65
Sreejit Pillai
  • 125
  • 4
  • 14

2 Answers2

5

Try like this:

void ScheduleNotificationForiOSWithMessage (string text, System.DateTime fireDate)
{
    if (Application.platform == RuntimePlatform.IPhonePlayer) {
        LocalNotification notification = new LocalNotification ();
        notification.fireDate = fireDate;
        notification.alertAction = "Alert";
        notification.alertBody = text;
        notification.hasAction = false;
        NotificationServices.ScheduleLocalNotification (notification);

        #if UNITY_IOS
        NotificationServices.RegisterForLocalNotificationTypes (LocalNotificationType.Alert | LocalNotificationType.Badge);
        #endif
    }        
}
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56
  • It is throwing this error. `UnityEngine.iOS.NotificationServices' does not contain a definition for `RegisterForLocalNotificationTypes' and what should i pass in the second parameter while calling this method. Thank you for replying. – Sreejit Pillai Jul 29 '15 at 10:09
  • for `what should i pass in the second parameter` you can pass `System.DateTime.Now.AddSeconds(5f);` this is the date when notification should appear. – NeverHopeless Jul 29 '15 at 11:41
0

You have to call "NotificationServices.RegisterForNotifications" first. See => Unity Documentation

Marius Junak
  • 1,203
  • 10
  • 17
  • Hello Marius, Thank you for replying. I just want scheduled local notifications . i dont want any notifications from a provider – Sreejit Pillai Jul 29 '15 at 09:19
  • 1
    "Register to receive local **and** remote notifications of the specified types from a provider via Apple Push Service." You have to register for local notifications aswell. – Marius Junak Jul 29 '15 at 09:32
  • The type or namespace name `iOS' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference? The type or namespace name `iOS' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference? it is showing these errors on importing the namespace as show in the documentation – Sreejit Pillai Jul 29 '15 at 10:11
  • I assume you are using Unity4. => The namespace changed in Unity5 In Unity4 use NotificationServices.RegisterForLocalNotificationTypes instead – Marius Junak Jul 29 '15 at 11:43