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

直接上代码

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>
#import <CoreLocation/CoreLocation.h>
@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 请求权限封装类的实例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

您可能感兴趣的文章:

  • 详解适配iOS10 的相关权限设置
(0)

相关推荐

  • 详解适配iOS10 的相关权限设置

    在最新版本的iOS10系统中,如果你的项目中访问了隐私数据,比如:相机.相册.录音.定位.联系人等等.涉及到权限问题. 解决办法(fix method): 在info.plist -Source Code中添加 UsageDescription相关的key, 描述字符串自己随意填写就可以,但是一定要填写,不然会引发包无效的问题,导致上传打包后构建版本一直不显示. <!-- 相册 --> <key>NSPhotoLibraryUsageDescription</key>

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

    直接上代码 #import <Foundation/Foundation.h> #import <AVFoundation/AVFoundation.h> #import <AssetsLibrary/AssetsLibrary.h> #import <Photos/Photos.h> #import <CoreLocation/CoreLocation.h> @interface PermissionUtil : NSObject +(Bool

  • java读取http请求中的body实例代码

    在http请求中,有Header和Body之分,读取header使用request.getHeader("..."); 读取Body使用request.getReader(),但getReader获取的是BufferedReader,需要把它转换成字符串, 下面是转换的方法. public static String getBodyString(BufferedReader br) { String inputLine; String str = ""; try {

  • IOS中各种手势操作实例代码

    先看下效果 手势相关的介绍 IOS中手势操作一般是 UIGestureRecognizer 类的几个手势子类去实现,一般我们用到的手势就这么5种: 1.点击  UITapGestureRecognizer 2.平移  UIPanGestureRecognizer 3.缩放  UIPinchGestureRecognizer 4.旋转  UIRotationGestureRecognizer 5.轻扫  UISwipeGestureRecognizer 我们上面这个实例中就用到了上面这5种手势,不

  • iOS 增加右侧按钮功能实例代码

    一,工程图. 二,代码. ViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //增加右侧按钮 [self addRightButton]; } #pragma -mark -functions //增加右侧按钮 -(void)addRightButton { UIBarButtonI

  • iOS清除所有缓存的实例代码

    本文介绍了iOS清除所有缓存的实例代码,分享给大家,具体如下: 计算缓存 NSString *libPath = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0]; CGFloat fileSize=[self folderSizeAtPath:libPath]; - (float ) folderSizeAtPath:(NSString*) folderPath{ NSFileMa

  • Android Okhttp请求查询购物车的实例代码

    查询购物车的model层 public class SelectCarModel { private String url="http://120.27.23.105/product/getCarts"; private HashMap<String, String> map = new HashMap<>(); public void verifySelectCarInfo(int uid, final ISelectCarPresenter iSelectC

  • app 请求服务器json数据实例代码

    请求服务器json数据格式代码,详细如下: var url=obj.serUrl; //此处为请求服务器的路径url,放上自己的请求路径: var data = {//date里面携带参数,根据服务器要求填写好参数,看清楚是字符串类型,还是整型. action:'getUser', username:loginInfowode, password:passwordwode }; //以下就是进入ajax请求服务器数据: mui.ajax({ type:"post",//请求格式,分为p

  • ios中getTime()的兼容性实例代码

    时间格式为:2017-12-12 12:00:00在苹果上获取时间戳有兼容性问题 需要转换成2017/12/12 12:00:00 才可以正确获取到时间戳 let u = navigator.userAgent; //判断浏览器型号 let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端 let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X

  • vue 请求后台数据的实例代码

    需要引用vue-resource 安装请参考https://github.com/pagekit/vue-resource官方文档 在入口函数中加入 import VueResource from 'vue-resource' Vue.use(VueResource); 在package.json文件中加入 "dependencies": { "vue": "^2.2.6", "vue-resource":"^1.2

  • iOS 9 Core Spotlight搜索实例代码

    前言 感觉 Spotlight 这个功能还是蛮有用的,能提升用户活跃,增加应用内容曝光几率. 正文 一.实现(iOS 9.0) 1.1 添加索引 var searchableItems = [CSSearchableItem]() for app in apps { let searchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String) searchableItem

随机推荐