gpt4 book ai didi

ios - 警告 : Application delegate received call to

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:33:53 30 4
gpt4 key购买 nike

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

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) 返回;

修复此错误应该会消失。

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];
}

关于ios - 警告 : Application delegate received call to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35766398/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com