如何使用通知请求禁用视图?

How can make disable view with Notification request?

如何开启和关闭本地通知?

当我第一次打开应用程序时,会出现这个带有通知请求的视图。如何在应用程序开始时让这个 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 的动作