gpt4 book ai didi

ios - 如何处理用户选择通知设置权限警报

转载 作者:行者123 更新时间:2023-11-28 21:13:43 24 4
gpt4 key购买 nike

在某些 View Controller 中,我弹出这个通知设置消息:

My app would like to to send you Notifications which may include alerts, sounds and icon badges. These can be configured in Settings

如何处理消息的 Don't AllowAllow 按钮?

如果用户点击允许,我需要在同一个 View Controller 中更改标签文本。

最佳答案

我假设您的应用中某处有这样的代码:

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:... categories:...];
[application registerUserNotificationSettings:settings];

这样做之后,系统将显示您正在谈论的警报。在那一刻,应用程序将收到 UIApplicationWillResignActiveNotification(您可以在应用程序委托(delegate)中或通过 NSNotificationCenter 注册)。然后,在用户做出选择后,系统将发送 UIApplicationDidBecomeActiveNotification(也在应用程序委托(delegate)中或通过通知)。此时,使用如下代码检查权限:

UIUserNotificationSettings *settings = application.currentUserNotificationSettings;
if (settings.types & UIUserNotificationTypeSound & UIUserNotificationTypeBadge) {
// sound and icon badge allowed
}
else {
// either sound or icon badge or both disallowed
}

关于ios - 如何处理用户选择通知设置权限警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42191549/

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