假设您要创建一个带有重复间隔的通知,以便重复发生
var
MyNotification : TNotification;
begin
MyNotification := NotificationCenter1.CreateNotification;
try
MyNotification.Name := 'FirstNotification';
MyNotification.AlertBody := 'First Notification!';
MyNotification.FireDate := IncSecond(Now,15);// Note this fires 15 secs from NOW
MyNotification.RepeatInterval := TRepeatInterval.Minute;
Notificationcenter1.ScheduleNotification(MyNotification);
finally
MyNotification.DisposeOf;
end;
在我的情况下,经常会提醒用户回复通知,然后一旦用户响应TNotificationCenters OnReceiveLocalNotification
上的通知,我只需取消通知
NotificationCenter1.CancelNotification(ANotification.Name);
这取消了通知并且它有效(种类)
现在上面的示例将创建一个通知,如果没有响应则每分钟一次将再次触发,并再次响应。
但现在的问题是,如果我要创建另一个我也想重复的通知:
var
MyNotification2 : TNotification;
begin
MyNotification2 := NotificationCenter1.CreateNotification;
try
MyNotification2.Name := 'SecondNotification';
MyNotification2.AlertBody := 'Second Notification!';
MyNotification2.FireDate := IncSecond(Now,30);// Note this fires 30 secs from NOW
MyNotification2.RepeatInterval := TRepeatInterval.Minute;
Notificationcenter1.ScheduleNotification(MyNotification2);
finally
MyNotification2.DisposeOf;
end;
如果第二个通知的FireDate设置为晚于第一个,那么一切都正常,并且如预期的那样花花公子,但是如果我要使用像IncSecond(Now,10)
这样的FireDate创建第二个通知意味着它将会在第一次预定通知出错之前开火
var
MyNotification2 : TNotification;
begin
MyNotification2 := NotificationCenter1.CreateNotification;
try
MyNotification2.Name := 'SecondNotification';
MyNotification2.AlertBody := 'Second Notification!';
MyNotification2.FireDate := IncSecond(Now,10);// Note this fires 10 secs from NOW
MyNotification2.RepeatInterval := TRepeatInterval.Minute;
Notificationcenter1.ScheduleNotification(MyNotification2);
finally
MyNotification2.DisposeOf;
end;
第一次通知永远不会到达,NotificationCenter1.CancelNotification(ANotification.Name);
不再删除第二条通知
CancelNotification
现在对SecondNotification
更新1
我可以确认代码在iOS中完全正常工作(没有意外行为),所以这是与Android相关的问题,
我在运行5.0.2的Xperia Z2和运行4.4.2的Samsung Note 2上尝试过它,行为完全相同