本地通知并不总是发送

Local Notification not always sending

我设置了一个 本地通知 每天在 7:45:01 下午触发,但 不是每天触发时间.

知道我在这里遗漏了什么吗?我已经尝试编辑代码,但仍然不知道我遗漏了什么。

能否post需要任何额外的代码,谢谢!

AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }

    return YES;
}

ViewController.m:

- (void)viewDidLoad {
    [super viewDidLoad];

    UILocalNotification* localNotification = [[UILocalNotification alloc] init];

    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *comp = [cal components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:[NSDate date]];
    comp.hour = 19; // 19 = 7PM
    comp.minute = 45; // 7:45 PM
    comp.second = 01; // 7:45:01 PM

    localNotification.fireDate = [cal dateFromComponents:comp];
    localNotification.alertBody = @"Local Notification in iOS8";
    localNotification.timeZone = [NSTimeZone defaultTimeZone];

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

I set up a Local Notification to fire off at 7:45:01 PM every day

不,你没有。您将本地通知设置为触发 一次。您没有设置任何 repeatInterval,因此这不是重复通知。它触发一次,仅此而已。