我正在我的应用程序中实现本地通知。在屏幕上,我随时间放置了两个文本字段。例如,第一个文本字段为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; //根据需要在午餐时间设置日期
  • 关于ios - 两个本地通知未触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20067672/

    10-14 20:04
    查看更多