资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

iOS请求权限封装类的实例代码

直接上代码

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站建设、成都网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的海林网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

#import 
#import 
#import 
#import 
#import 
@interface PermissionUtil : NSObject
+(Boolean)JudgeCameraPermission;
+(Boolean)JudgeLocationPermission;
@end
#import "PermissionUtil.h"
@implementation PermissionUtil

+(BOOL)isCanUsePhotos {
 if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
  ALAuthorizationStatus author =[ALAssetsLibrary authorizationStatus];
  if (author == kCLAuthorizationStatusRestricted || author == kCLAuthorizationStatusDenied) {
   //无权限
   return NO;
  }
 }
 else {
  PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
  if (status == PHAuthorizationStatusRestricted ||
   status == PHAuthorizationStatusDenied) {
   //无权限
   return NO;
  }
 }
 return YES;
}

+(Boolean)JudgeCameraPermission{
 AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
 if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied||![self isCanUsePhotos])
 {
  return NO;
 }
 return YES;
}

+(Boolean)JudgeLocationPermission{
 if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {
  return YES;
 }else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {
  return NO;
 }
 return NO;
}
@end

以上这篇iOS 请求权限封装类的实例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持创新互联。


名称栏目:iOS请求权限封装类的实例代码
标题路径:http://cdkjz.cn/article/pogpoo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220