gpt4 book ai didi

ios - 当应用程序处于后台时无法删除通知

转载 作者:行者123 更新时间:2023-11-29 05:31:01 24 4
gpt4 key购买 nike

您好,当我的应用程序位于后台并且静默推送到达时,我正在尝试从通知中心删除通知。如果应用程序位于前台或连接到调试器,它可以正常工作。

但是,当应用程序在后台运行时,它就不起作用。我在 didReceiveRemoteNotification 内的 removeDeliveredNotificationsWithIdentifiers 中使用。有什么建议吗?谢谢您

[center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {

for (UNNotification* notification in notifications)
{
NSDictionary* ui = notification.request.content.userInfo;

if ([ui[@"activityId"] isEqualToString:activityId])
{
[center removeDeliveredNotificationsWithIdentifiers:@[notification.request.identifier]];
}

}
completionHandler(UIBackgroundFetchResultNoData);
}];

最佳答案

尝试使用 UIApplicationState 属性。

示例:

  UIApplicationState* applicationState;
if (applicationState == UIApplicationStateActive) {
// Application is running in foreground
//Handler
}
else if (applicationState == UIApplicationStateBackground || applicationState == UIApplicationStateInactive) {
// Application is brought from background or launched after terminated
// Handler
}

关于ios - 当应用程序处于后台时无法删除通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57571224/

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