判断并打开系统设置

参考了这位博主的文章:


http://www.jianshu.com/p/19602f48309b

//在应用活跃的时候判断系统设置中的通知是否打开

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

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

          if (SYSTEM_VERSION < 8.0) {

            if ([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone && !titleView) {

                titleView = [[SFGlobalAlertView alloc] initWithMessage:@"检测到系统禁止了消息推送,这样会导致您无法及时收到消息" delegate:self type:GlobalAlertViewTypeDefault];

                [titleView setLeftButtonTitle:@"立即设置" imageWithNormalImageName:nil

                           highlightImageName:nil];

                [titleView setRightButtonTitle:@"不再提醒" imageWithNormalImageName:nil highlightImageName:nil];

                titleView.tag = SFGlobalViewTagForNotiSetting;

                [titleView show];

                

            }

            

        }else

        {

            UIUserNotificationType types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;

           

            if (types == UIUserNotificationTypeNone && !titleView) {

                 titleView = [[SFGlobalAlertView alloc] initWithMessage:@"检测到系统禁止了消息推送,这样会导致您无法及时收到消息" delegate:self type:GlobalAlertViewTypeDefault];

                [titleView setLeftButtonTitle:@"立即设置" imageWithNormalImageName:nil

                           highlightImageName:nil];

                [titleView setRightButtonTitle:@"不再提醒" imageWithNormalImageName:nil highlightImageName:nil];

                [titleView show];

                titleView.tag = SFGlobalViewTagForNotiSetting;

            }

        }

  }

  

//如果没有打开,则进入设置

    if(SYSTEM_VERSION < 8.0)

           {

               [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=INTERNET_TETHERING"]];


           }else

         {

                 NSURL *url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];

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

                 

                 [[UIApplication sharedApplication] openURL:url];

                 

             }


         }


  



转载于:https://my.oschina.net/daxiaLKS/blog/542657

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值