IOS APP权限获取

iOS 判断是否开启定位

+ (BOOL)isLocationServiceOpen {
   if ([ CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
       return NO; 
    } else 
       return YES;
}

iOS 判断是否允许消息通知

- ios10以及之后版本
+ (void)isMessageNotificationServiceOpenBlock:(void (^)(BOOL))block{
    
    if ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0) {
        
        [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
            
            NSLog(@"setting = %@",settings);
            
            if(settings.authorizationStatus == UNAuthorizationStatusAuthorized){
                
                if (block) {
                    
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"没有打开通知权限" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", @"取消", nil];
                    
                    alertView.delegate = self;
                    
                    [alertView show];
                    
                    block(true);
                }
        
            } else {
                
                if (block) {
                    block(false);
                }
            }
        }];
        //        return true;
    } else if (SYSTEM_VERSION_GREATER_THAN(@"8.0") {
        
        if (block) {
            block([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]);
        }
        
    } else {
        
        if (block) {
            block(UIRemoteNotificationTypeNone != [[UIApplication sharedApplication] enabledRemoteNotificationTypes]);
        }
    }
}
- ios10之前版本
+ (BOOL)isMessageNotificationServiceOpen { 
       if (SYSTEM_VERSION_GREATER_THAN(@"8.0")) {
              BOOL pushEnabled;
// 设置里的通知总开关是否打开
              BOOL settingEnabled = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
// 设置里的通知各子项是否都打开
              BOOL subsettingEnabled = [[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone;pushEnabled = settingEnabled && subsettingEnabled;
 return pushEnabled; 
      } else { 
             return UIRemoteNotificationTypeNone != [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 
       }
}

iOS 跳转系统设置打开定位页面

if (SYSTEM_VERSION_GREATER_THAN(@"8.0")) { 
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; 
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
                    [[UIApplication sharedApplication] openURL:url]; 
         } 
 } else {
         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]]; 
 }

iOS 跳转系统设置打开消息页面

if (SYSTEM_VERSION_GREATER_THAN(@"8.0")) { 
     NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; 
     if ([[UIApplication sharedApplication] canOpenURL:url]) {
           [[UIApplication sharedApplication] openURL:url]; 
      }
 } else { 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=NOTIFICATIONS_ID"]]; 
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,192评论 4 61
  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,522评论 7 249
  • 给自己放假之后,回来。各种压力迎面而来。工作,家庭。 公司内部,各个股东的勾心斗角。施工方的各种问题,客户的各种问...
    時光流轉阅读 183评论 0 0
  • 你以为我不知道吗?其实你还在做完一些事情,只是我不知道在这深夜里,你是在逃避孤独,还是享受孤独,这个答案估计你自己...
    简野文馆阅读 344评论 3 9
  • 多少次想要写下一些自己的想法和经历,可是都在自己那些看似强大的理由下搁浅了。这次徐水之行,从君姐身上看到了...
    简行0阅读 331评论 2 3