Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用通知请求禁用视图?_Ios_Iphone_Notifications - Fatal编程技术网

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

Ios 如何使用通知请求禁用视图?,ios,iphone,notifications,Ios,Iphone,Notifications,如何激活和禁用本地通知 当我第一次打开应用程序时,此视图将显示通知请求。如何在应用程序开始时使此alertView消失以进行通知?我想在设置中使用一个开关 那么,这是一种从AppDelegate转换代码的方法,从settingsView转换而来 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedApplication] registerUserNotif

如何激活和禁用本地通知

当我第一次打开应用程序时,此视图将显示通知请求。如何在应用程序开始时使此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)];
}

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

在setingsview.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的操作

可能过了一段时间,用户希望更改为打开或关闭。权限警报只出现一次。您不能以编程方式显示权限警报。请参阅苹果关于通知永久性的指南。一旦用户不允许向您的应用发送通知,您就不能发送通知,也不能再次请求永久性。按照苹果公司的说法,这让用户很恼火。