ios系列——权限

定位权限

参考http://www.cnblogs.com/kenshincui/p/4125570.html

_locationManager=[[CLLocationManager alloc]init];
if (![CLLocationManager locationServicesEnabled]) {
         NSLog(@"系统没有打开定位功能");
        return;
    }

CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if (status==kCLAuthorizationStatusDenied){
     NSLog(@"app没有权限");

//据说这个能在没有权限使用定位的情况下可以重新弹出权限设置 不过测试没成功
        [_locationManager requestWhenInUseAuthorization];
    }
  • 说明
typedef NS_ENUM(int, CLAuthorizationStatus) {
//          用户尚未做出选择这个应用程序的问候
        kCLAuthorizationStatusNotDetermined = 0,

        //       此应用程序没有被授权使用位置服务。由于对位置服务的活动限制,用户不能更改
        //这一状态,并可能不是亲自否认授权  可能是家长控制权限
        kCLAuthorizationStatusRestricted,

//        用户已明确地拒绝了该应用程序的授权,或
//        在设置中禁用位置服务。
        kCLAuthorizationStatusDenied,

//        用户已授予授权其在任何时间使用位置  (8.0系统以后才有)
        kCLAuthorizationStatusAuthorizedAlways NS_ENUM_AVAILABLE(NA, 8_0),

//        用户已授予授权其在使用app的时间使用位置  (8.0系统以后才有)
        kCLAuthorizationStatusAuthorizedWhenInUse NS_ENUM_AVAILABLE(NA, 8_0),

//         过期的数据(2.0-8.0可使用) 相当于8.0的 kCLAuthorizationStatusAuthorizedAlways
        kCLAuthorizationStatusAuthorized NS_ENUM_DEPRECATED(10_6, NA, 2_0, 8_0, "Use kCLAuthorizationStatusAuthorizedAlways") = kCLAuthorizationStatusAuthorizedAlways
    };

相册使用权限

7.0以上的方法 7.0一下 没有权限一说
- 导入头文件

#import <AssetsLibrary/AssetsLibrary.h>
  • 调用以下代码
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
            if (author == kCLAuthorizationStatusRestricted || author == kCLAuthorizationStatusDenied)
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"以拒绝此运用使用相机,请进入设置-隐私-相机 打开使用权限" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alert show];
                return;
            }
  • 说明
typedef enum {
    kCLAuthorizationStatusNotDetermined = 0, // 用户尚未做出选择这个应用程序的问候
    kCLAuthorizationStatusRestricted,        // 此应用程序没有被授权访问的照片数据。可能是家长控制权限
    kCLAuthorizationStatusDenied,            // 用户已经明确否认了这一照片数据的应用程序访问
    kCLAuthorizationStatusAuthorized         // 用户已经授权应用访问照片数据
} CLAuthorizationStatus;

相机使用权限

7.0以上的方法 7.0一下 没有权限一说

  • 导入头文件
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
  • 代码调用
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
            if (authStatus != AVAuthorizationStatusAuthorized)
            {
                //无权限
            }
  • 说明
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
                AVAuthorizationStatusNotDetermined = 0, //            指示用户尚未对该客户机是否访问作出选择。
                AVAuthorizationStatusRestricted,        //            此应用程序没有被授权访问。可能是家长控制权限
                AVAuthorizationStatusDenied,            //            用户明确地拒绝了为客户端支持媒体类型的硬件访问。
                AVAuthorizationStatusAuthorized         //            客户端被授权访问硬件支持的媒体类型。
            } NS_AVAILABLE_IOS(7_0);

消息通知权限

  • 如果是ios8.0以上系统
UIUserNotificationSettings *mySet = [[UIApplication sharedApplication] currentUserNotificationSettings];
  • 做判断的时候应该这样写
if (mySet.types == (UIUserNotificationTypeBadge | UIUserNotificationTypeSound)) {}
  • 说明
//        typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
//            UIUserNotificationTypeNone    = 0,      // 应用程序可能不存在任何UI在通知接收
//            UIUserNotificationTypeBadge   = 1 << 0, // 应用程序可在收到通知时图标会被标记
//            UIUserNotificationTypeSound   = 1 << 1, // 应用程序可在收到通知后发出声音
//            UIUserNotificationTypeAlert   = 1 << 2, // 应用程序可在收到通知后显示提示
//        } NS_ENUM_AVAILABLE_IOS(8_0);

如果是8.0一下的系统

UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
  • 做判断的时候应该这样写
if (status == (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)) {}
  • 说明
 typedef enum {
     UIRemoteNotificationTypeNone = 0,
     UIRemoteNotificationTypeBadge = 1 << 0,
     UIRemoteNotificationTypeSound = 1 << 1,
     UIRemoteNotificationTypeAlert = 1 << 2,           UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3,
} UIRemoteNotificationType;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值