警告:应用程序委托收到调用

Warning: Application delegate received call to

我正在实施本地通知方法,但我收到了警告

Warning: Application delegate received call to -application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler: but the completion handler was never called.

这是我在 didfinishlaunchmethod 中的代码

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {



        UIMutableUserNotificationAction *snooze=[[UIMutableUserNotificationAction alloc] init];
        [snooze setActivationMode:UIUserNotificationActivationModeBackground];
        [snooze setTitle:@"Snooze"];
        [snooze setIdentifier:NotificationActionOneIdent];
        [snooze setDestructive:NO];
        [snooze setAuthenticationRequired:YES];

        UIMutableUserNotificationAction *cancel=[[UIMutableUserNotificationAction alloc] init];
        [cancel setActivationMode:UIUserNotificationActivationModeBackground];
        [cancel setTitle:@"Cancel"];
        [cancel setIdentifier:NotificationActionTwoIdent];
        [cancel setDestructive:NO];
        [cancel setAuthenticationRequired:YES];

        UIMutableUserNotificationCategory *actionCategory;
        actionCategory = [[UIMutableUserNotificationCategory alloc] init];
        [actionCategory setIdentifier:NotificationCategoryIdent];
        [actionCategory setActions:@[cancel, snooze]
                        forContext:UIUserNotificationActionContextDefault];

        NSSet *categories = [NSSet setWithObject:actionCategory];

        UIUserNotificationType types = (UIUserNotificationTypeAlert|
                                        UIUserNotificationTypeSound|
                                        UIUserNotificationTypeBadge);

        UIUserNotificationSettings *settings;
        settings = [UIUserNotificationSettings settingsForTypes:types
                                                     categories:categories];

        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

这是完成处理程序的代码

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler
 {
    NSLog(@"called");
    if ([identifier isEqualToString:NotificationActionOneIdent]) {


        NSLog(@"You choose snooze");
        UILocalNotification *localNotif = [[UILocalNotification alloc] init];
        if (localNotif == nil) return;

        NSDate *fireTime = [[NSDate date]   dateByAddingTimeInterval:900];

        localNotif.fireDate = fireTime;
        localNotif.alertBody = @"Time to wake up";
        localNotif.repeatInterval=kCFCalendarUnitMinute;
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];


    }
    else if ([identifier isEqualToString:NotificationActionTwoIdent]) {

        NSLog(@"You choose cancel");
    }

        completionHandler();
}

但是我一次又一次收到同样的警告..请帮我解决这个问题。

你在不调用 completionHandler()

的句柄函数中有一个退出点

if (localNotif == nil) return;

修复此错误应该会消失。

if (localNotif != nil) {
        NSDate *fireTime = [[NSDate date]   dateByAddingTimeInterval:900];
        localNotif.fireDate = fireTime;
        localNotif.alertBody = @"Time to wake up";
        localNotif.repeatInterval=kCFCalendarUnitMinute;
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}