欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2024-02-12 14:59:46
直接上代码 #import #import

直接上代码

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