iOS Local Notifications Testing
In testing my local notifications, for some reason setting the date and time on my iOS device does not trigger my local notification to appear. My notification's fire date is set to be several days in the future. If I do wait a few days then I will see my local notification.
Why am I not seeing my local notification by setting the date and time on my device?
Below is a sample:
playNotification.FireDate = DateTime.Now.AddHours(71.67f); playNotification.AlertAction = "Alert text"; playNotification.AlertBody = "Alert body"; playNotification.SoundName = UILocalNotification.DefaultSoundName; playNotification.ApplicationIconBadgeNumber = badgeCount; UIApplication.SharedApplication.ScheduleLocalNotification(playNotification);
I should mention that I changed 'AddHours' to 'AddSeconds' and tested this by waiting the specified number of seconds, and the notifications fired as expected. But somehow changing the date and time on my device does not.
You need to set the timeZone of the notifications. By default, the timeZone is set according to your location so it does not affect if you manually change your date and time. To achieve this, you need to set the timeZone to systemTimeZone().
notification.timeZone = NSTimeZone.systemTimeZone()
I know this is in swift, but I know very little objective-c. Hope this helps. :)