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 请求权限封装类的实例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
上一篇: JSON在ASP.NET中使用方法