简体   繁体   中英

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?

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

localNotif.timeZone = [NSTimeZone systemTimeZone];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM