iOS推送通知关闭

- (void)registerRemoteNotification:(UIApplication *)application{

    

    

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0)

    {

        //iOS10特有

        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

        // 必须写代理,不然无法监听通知的接收与点击

        center.delegate = self;

        [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {

            if (granted) {

                // 点击允许

                DLog(@"注册成功");

                [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {

                    NSLog(@"%@", settings);

                }];

            } else {

                // 点击不允许

                DLog(@"注册失败");

                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                   

                    [self performSelectorOnMainThread:@selector(getPushAlert) withObject:nil waitUntilDone:YES];

                });

 

                

                

            }

        }];

    }else if ([[UIDevice currentDevice].systemVersion floatValue] >8.0){

        //iOS8 - iOS10

//        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge categories:nil]];

        UIUserNotificationSettings *setting=[[UIApplication  sharedApplication] currentUserNotificationSettings];

        if (UIUserNotificationTypeNone!=setting.types) {

              DLog(@"注册成功");

        }

        else

        {

              DLog(@"注册失败");

这里必须要避开主线程

            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                

                [self performSelectorOnMainThread:@selector(getPushAlert) withObject:nil waitUntilDone:YES];

            });

          

        }

        

        

    }else if ([[UIDevice currentDevice].systemVersion floatValue] < 8.0) {

//         UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

//         if(UIRemoteNotificationTypeNone != type) {

//               DLog(@"注册成功");

//        }else{

//               DLog(@"注册失败");

//        }

        

 

    }

    // 注册获得device Token

//    [[UIApplication sharedApplication] registerForRemoteNotifications];

}

 

 

-(void)getPushAlert{

    UIAlertView *alert = [[UIAlertView alloc]

                          initWithTitle:@"温馨提示"

                          message:@"未开启通知,会错过很多重要信息。请到【设置】中开启"

                          delegate:self

                          cancelButtonTitle:nil

                          otherButtonTitles:@"确定", nil];

    

    alert.tag = 111;

    

    [alert show];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值