我正在我的应用中实施本地通知。在一个屏幕上,我放置了两个文本字段,随着时间的推移。例如,第一个文本字段具有2.44pm,第二个文本字段具有2.45pm。第一个文本字段的本地通知时间没有在下午2点44分开始。但是下午2点45分的通知是正确的。并且,下午2点44分通知显示。
// 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;
}
我错了吗? 提前谢谢。
答案 0 :(得分:1)
根据您的需要进行更改:
FOR MorningTimelbl.text
notif.fireDate = Morningtime-date;
//在Morningtime-date FOR next(second-Notification)LunchTimelbl.text
notif.fireDate = LunchTime-date;
//在LunchTime-date