seaders
seaders

Reputation: 4096

Trigger local notification set from scheduleLocalNotification

In our app, if a user has set a reminder from us for the future, we set a local notification via,

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) return;
NSDate *fireTime = [[NSDate date] addTimeInterval: 60 * 60]; // adds 1 hour (60 seconds * 60 minutes)
localNotif.fireDate = fireTime;
localNotif.alertBody = @"Alert!";

[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

Obviously this is easy to test if it's just a few seconds / minutes, but to test 100% when it's scheduled for far in the future, for us to test that, is our only option to just wait?

On Android, you're able to simply adjust the date and time of the phone, and that triggers the local notification, but thus far, I can't see any way to do it on iOS.

Is there a way to?

Upvotes: 0

Views: 302

Answers (1)

strwils
strwils

Reputation: 687

You need to set the timeZone property of the UILocalNotification. Otherwise, the notification is simply a countdown timer.

localNotif.timeZone = [NSTimeZone systemTimeZone];

Upvotes: 1

Related Questions