gpt4 book ai didi

ios - 应用程序 :didReceiveLocalNotification: not called when app in background

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:06:29 24 4
gpt4 key购买 nike

当我的应用程序进入后台时,系统会自动调用 applicationDidEnterBackground 并在该方法中触发本地通知。但是 didReceiveLocalNotification: 方法没有被调用

- (void)applicationDidEnterBackground:(UIApplication *)application {

UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
bgTask = UIBackgroundTaskInvalid;
}];

UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.fireDate = [NSDate date];
localNotification.alertBody = textString;
localNotification.alertAction = @"View";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;

[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}

最佳答案

您对本地通知的期望不正确:

当您的应用进入后台时,您会在手机上看到一条即时通知,但您必须点击该通知才能触发 didReceiveLocalNotification 委托(delegate)。

如果您在前台收到本地通知,则会自动触发 didReceiveLocalNotification。

以上场景已经过测试和验证。

更新:您必须阅读此文档: http://www.thekspace.com/home/component/content/article/62-uilocalnotification-demystified.html

关于ios - 应用程序 :didReceiveLocalNotification: not called when app in background,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31002969/

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