NotificationServices: Local Notifications not working

I’m trying to get Local Notifications to work, so I’m using NotificationServices to send local notifications.

Since sending a scheduled notification didn’t seem to work, I decided to try sending an immediate notification. I made a button fire the following code when pressed:

var notif = new LocalNotification();
		notif.alertBody = "Test body!";
		NotificationServices.PresentLocalNotificationNow(notif);
		Debug.Log ("***Notification sent!");

When the button is pressed, while running on my iPad from Xcode, nothing happens (except for the Debug.Log statement).

Has anyone gotten LocalNotifications to work successfully, and if so how?

This code worked for me as a test (executed from a debug button in the app).

			var n = new LocalNotification();
			n.fireDate = DateTime.Now.AddSeconds(10);
			n.alertAction = "Title Here";
			n.alertBody = "My Alert Body Text";
			n.applicationIconBadgeNumber = 99;
			n.hasAction = true;//?
			n.repeatCalendar = CalendarIdentifier.GregorianCalendar;
			n.repeatInterval = CalendarUnit.Day;
			n.soundName = LocalNotification.defaultSoundName;
			NotificationServices.ScheduleLocalNotification(n);

Thank you so much! You’re a lifesaver!

After testing a little bit, it looks like hasAction doesn’t default to true.

andymads, Arktor314

Thanks for the example, but unfortunately, this code doesn’t work for me either. I’m not receiving any notifications. Is there anything else I’m missing?

What exactly do I have to do besides using that code to get it to work? The documentation isn’t mentioning anything, but maybe I need to change something in the app settings through XCode? Or maybe I need to add some more code elsewhere? Or maybe I need to add certain frameworks to the app?

At the moment, the notification is just completely absent no matter the lock state of the phone and no matter the state of the app (paused, closed). Unfortunately it’s extremely hard to find any information about local notifications on the net besides official Unity and XCode docs as absolute majority of questions and threads are dedicated to push notifications which aren’t exactly what I need.

As far as I know there’s nothing else to do.

Silly question perhaps, but are you actually executing this code?

Yes, it’s being executed as all lines before and after it doing other stuff are working, and Debug.Log I’ve added specifically to that place fires correctly.

It’s good to hear nothing else is required, though. I have one last suspect then - System.DateTime. I’m building XCode projects from Windows and I’ve heard that Unity 4.3 has some serious issues with System.DateTime in iOS builds created from Windows-originating XCode projects. Perhaps the notification is scheduled correctly, it’s just that Unity feeds it completely incorrect time, so I never see it. I’ll try building the project from Mac next time to compare the results.

Still, though. Shouldn’t an application appear in the Notification Center if it’s using local notifications? My application is not there.

hHello friend, what you guys there who know how to use alertLaunchImage?
This is on doc unity, but not explained how to use it.
would be good if there was more explanation about this.
and how to use custom sound?

I thank you in advance

I can confirm, root of the issue was faulty XCode project compilation from Windows version of the Editor. Building the project from OS X Editor fixed the issue. Shame. Hopefully Unity developers will fix it soon.

How do you catch LocalNotifications while in game? There is no documentation on this.

hii.
I am struggling with the same issue. Did u find any solution for the launch image and customizing notification?
Regarding your custom Sounds you need to place the sound in Xcode unity project folder and sound should be in the the format apple supports i.e aiff or wav etc. Also, sound should not be more than 30 sec.