关闭

IOS [推送相关] 在app 内获取系统设置页的通知开关状态,然后使app 和system 开关保持一致 【此功能只适用月IOS8 +】

标签: iosapp推送 系统设置页
1369人阅读 评论(0) 收藏 举报
分类:

关键代码

UIUserNotificationSettings *userNotificationSetting = [[UIApplication sharedApplication] currentUserNotificationSettings];
                   if( userNotificationSetting.types == UIUserNotificationTypeNone )

               {

                        //表示系统当前的通知开关是打开的

              }

详细代码示范:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                if(swh.isOn){//推送开关是打开的,注册远程通知
                    cactusAppDelegate *delegateCactus=(cactusAppDelegate *)[UIApplication sharedApplication].delegate;
                    [delegateCactus registerAPNSDirect];
                    [[NSUserDefaults standardUserDefaults] setInteger:EnablePush forKey:ifPush];
                    [[NSUserDefaults standardUserDefaults] synchronize];
                    [ISStat probePushSetting:@"pushon"];
                }
                else{
                    cactusAppDelegate *delegateCactus=(cactusAppDelegate *)[UIApplication sharedApplication].delegate;
                    [delegateCactus removeRemoteNotification];
                    [[NSUserDefaults standardUserDefaults] setInteger:DisenablePush forKey:ifPush];

                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    UIUserNotificationSettings *userNotificationSetting = [[UIApplication sharedApplication] currentUserNotificationSettings];
                    userNotificationSetting.types == UIUserNotificationTypeNone ?[swh setOn:NO animated:YES]:[swh setOn:YES animated:YES];

                    [self.tableView reloadData];
                    });
            });


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:10083次
    • 积分:183
    • 等级:
    • 排名:千里之外
    • 原创:9篇
    • 转载:0篇
    • 译文:0篇
    • 评论:2条
    文章分类
    文章存档
    最新评论