从 scheduleLocalNotification 触发本地通知集
Trigger local notification set from scheduleLocalNotification
在我们的应用中,如果用户设置了来自我们的未来提醒,我们会通过
设置本地通知
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];
显然这很容易测试,如果只是几秒/分钟,但是要在很远的将来测试 100%,对我们来说测试那个,我们唯一的选择就是等待吗?
在 Android,您可以简单地调整 phone 的日期和时间,这会触发本地通知,但到目前为止,我看不到任何方法在 iOS.
上做
有办法吗?
您需要设置 UILocalNotification
的 timeZone 属性。否则,通知只是一个倒数计时器。
localNotif.timeZone = [NSTimeZone systemTimeZone];
在我们的应用中,如果用户设置了来自我们的未来提醒,我们会通过
设置本地通知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];
显然这很容易测试,如果只是几秒/分钟,但是要在很远的将来测试 100%,对我们来说测试那个,我们唯一的选择就是等待吗?
在 Android,您可以简单地调整 phone 的日期和时间,这会触发本地通知,但到目前为止,我看不到任何方法在 iOS.
上做有办法吗?
您需要设置 UILocalNotification
的 timeZone 属性。否则,通知只是一个倒数计时器。
localNotif.timeZone = [NSTimeZone systemTimeZone];