[英]Two Local notifications Not Firing
我正在我的应用程序中实现本地通知。 在屏幕上,我随时间放置了两个文本框。 例如,第一个文本字段具有2.44 pm,第二个文本字段具有2.45pm。 第一个文本字段的本地时间通知不会在2.44 pm触发。 但2.45pm通知正确触发。 并且,2.44pm通知显示为2.45 pm。
// viewcontroller.m file
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil)
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
{
if ([MorningTimelbl.text length]>0)
{
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"It's time to take your eye drops";
notif.alertAction = @"Morning Notification";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
notif.repeatInterval = NSDayCalendarUnit;
NSDictionary *mornDict = [NSDictionary dictionaryWithObject:MorningTimelbl.text
forKey:kRemindMeNotificationDataKey];
notif.userInfo = mornDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
if ([LunchTimelbl.text length]>0)
{
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"It's time to take your eye drops";
notif.alertAction = @"Lunch Notification";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
notif.repeatInterval = NSDayCalendarUnit;
NSDictionary *lunchDict = [NSDictionary dictionaryWithObject:LunchTimelbl.text
forKey:kRemindMeNotificationDataKey];
notif.userInfo = lunchDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
}
//appdelegate.m
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder"
message:notification.alertBody
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
}
我在哪里弄错了? 提前致谢。
根据需要更改:
对于MorningTimelbl.text
notif.fireDate = Morningtime-date;
//根据需要在Morningtime-date设置日期 FOR next(second-Notification)LunchTimelbl.text
notif.fireDate = LunchTime-date;
//根据需要在午餐时间设置日期
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.