gpt4 book ai didi

ios - 查看后如何删除通知中心的推送通知

转载 作者:技术小花猫 更新时间:2023-10-29 11:23:20 27 4
gpt4 key购买 nike

有什么方法可以在点击后处理来自通知中心的推送通知,并在我的应用程序已经启动时将其删除?

最佳答案

我知道这是黑客和斜杠,但您可以通过更改应用程序上的角标(Badge)编号来清除所有通知。

- (void)application:(UIApplication*)application didReceiveRemoteNotification (NSDictionary*)payload
{
NSLog(@"Received notification: %@", payload);
//swapping between two badge numbers to clear notifications
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
...
}

如果你已经有一个你不想丢失的角标(Badge)号码(上面的例子最后会简单地清除角标(Badge)号码)你可以这样做

- (void)application:(UIApplication*)application didReceiveRemoteNotification (NSDictionary*)payload
{
NSLog(@"Received notification: %@", payload);
/*
storing current badge number then swapping between 2 values to make sure we
clear the badge number. Once this is done set badge number back to original
value.
*/
int badgeNum = [[UIApplication sharedApplication] applicationIconBadgeNumber]
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeNum];
...
}

这可能不是最佳实践,但它完成了工作并且客户不会知道其中的区别。我喜欢称它为临时工。修复,直到我偶然发现更好的解决方案。希望这对某人有帮助!

关于ios - 查看后如何删除通知中心的推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8206534/

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