gpt4 book ai didi

ios - 如何使用通知请求禁用 View ?

转载 作者:行者123 更新时间:2023-11-29 12:19:04 25 4
gpt4 key购买 nike

如何启用和禁用本地通知?

当我第一次打开应用程序时,会出现带有通知请求的 View 。如何在应用程序开始时让这个 alertView 消失以进行通知?我想为此在设置中使用一个开关。

那么,这是一种从 AppDelegate 转换此代码的方法,在 settingsView 的切换中?

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

或者我可以设置从开始到开启通知?在我使用开关创建或不创建通知之后。

最佳答案

在 settingsView.m 文件中试试这个

       - (IBAction)switchValueChanged:(id)sender
{
if (self.switchNotificationSetting.isOn)
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
}
}

第二次以后它不会显示警报,用户允许通知或不允许,警报只出现一次。你需要添加 iboutlet 和 uiswitch 的 Action

关于ios - 如何使用通知请求禁用 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31179747/

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