iOS应用内调用系统通知按钮控制是否接收推送消息

UISwitch*switchButton = [[UISwitchalloc]initWithFrame:CGRectMake(SCREEN_WIDTH-55,8,20,10)];

  [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {

                    if(settings.authorizationStatus==UNAuthorizationStatusNotDetermined)

                    {

                        NSLog(@"未选择---没有选择允许或者不允许,按不允许处理");

                        [switchButtonsetOn:NO];

                    }elseif(settings.authorizationStatus==UNAuthorizationStatusDenied){

                        NSLog(@"未授权--不允许推送");

                        [switchButtonsetOn:NO];

                    }elseif(settings.authorizationStatus==UNAuthorizationStatusAuthorized){

                        NSLog(@"已授权--允许推送");

                        [switchButtonsetOn:YES];

                    }

                }];

 [switchButtonaddTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];

   [celladdSubview:switchButton];

//推送开关点击事件

-(void)switchAction:(id)sender

{

    UISwitch*switchButton = (UISwitch*)sender;

    BOOLisButtonOn = [switchButtonisOn];

    if(isButtonOn) {

        NSLog(@"是");

//打开系统设置页面

        NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];


        if([[UIApplication sharedApplication] canOpenURL:url]) {


            NSURL *url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];


            [[UIApplication sharedApplication] openURL:url];

        }

    }else{

        NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];


        if([[UIApplication sharedApplication] canOpenURL:url]) {


            NSURL *url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];


            [[UIApplication sharedApplication] openURL:url];

        }

    }

}

你可能感兴趣的:(iOS应用内调用系统通知按钮控制是否接收推送消息)