1、App 权限 注意:
没加相关权限,程序可能直接崩溃!
网络 https
<!-- 网络https -->
<key>NSAppTransportSecurity</key>
<dict><key>NSAllowsArbitraryLoads</key><true/>
</dict>
相机相册
<!-- 相机 -->
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<!-- 相册 -->
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSAppleMusicUsageDescription</key>
<string>App需要访问您的相册,以便您获取或保存需要的图片资源。</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>我们要使用您的位置,以便为您提供学习服务。</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>App需要访问您的相册,以便您获取或保存需要的图片资源。</string>
蓝牙
<!-- 蓝牙 -->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能访问蓝牙</string>
通讯录
<!-- 通讯录 -->
<key>Privacy - Contacts Usage Description</key>
<string>App需要访问您的通讯录</string>
位置
<!-- 位置 -->
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<!-- 在使用期间访问位置 -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期间访问位置</string>
<!-- 始终访问位置 -->
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
语音
<!-- 语音识别(语音转文字) -->
<key>Privacy - Speech Recognition Usage Description </key>
<string>App需要使用语音识别</string>
<!-- 麦克风 -->
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
其他不常用
<!-- 日历 -->
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能访问日历</string>
<!-- 提醒事项 -->
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能访问提醒事项</string>
<!-- 运动与健身 -->
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能访问运动与健身</string>
<!-- 健康更新 -->
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<!-- 健康分享 -->
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string> <!-- Siri -->
<key>Privacy - Siri Usage Description</key>
<string>App需要使用您的Siri功能</string>
<!-- 电视供应商 -->
<key>Privacy - TV Provider Usage Description</key>
<string>App需要使用您的电视供应商功能</string>
<!-- 视频用户账号 -->
<key>Privacy - Video Subscriber Account Usage Description</key>
<string>App需要使用您的视频用户账号</string>
是否开启权限
判断是否开启相机权限
系统说明
/*!@enum AVAuthorizationStatus@abstractConstants indicating the client's authorization to the underlying hardware supporting a media type.@constant AVAuthorizationStatusNotDeterminedIndicates that the user has not yet made a choice regarding whether the client can access the hardware.@constant AVAuthorizationStatusRestrictedThe client is not authorized to access the hardware for the media type. The user cannot change the client's status, possibly due to active restrictions such as parental controls being in place.@constant AVAuthorizationStatusDeniedThe user explicitly denied access to the hardware supporting a media type for the client.@constant AVAuthorizationStatusAuthorizedThe client is authorized to access the hardware supporting a media type.*/@摘要
常数,指示客户端对支持媒体类型的底层硬件的授权。
@ AVAuthorizationStatusNotDetermined
表示用户尚未选择客户端是否可以访问硬件。
@ AVAuthorizationStatusRestricted
客户端无权访问媒体类型的硬件。用户无法更改客户端的状态,可能是由于家长控制等活动限制。
@ AVAuthorizationStatusDenied
用户明确拒绝访问支持客户端媒体类型的硬件。
@ AVAuthorizationStatusAuthorized
客户机被授权访问支持媒体类型的硬件。
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {AVAuthorizationStatusNotDetermined = 0,AVAuthorizationStatusRestricted = 1,AVAuthorizationStatusDenied = 2,AVAuthorizationStatusAuthorized = 3,
} API_AVAILABLE(macos(10.14), ios(7.0), macCatalyst(14.0)) API_UNAVAILABLE(tvos) __WATCHOS_PROHIBITED;
oc
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>//相机是否可用
+ (BOOL)getCreame {AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];switch (status) {//相机不可用case AVAuthorizationStatusNotDetermined: //尚未选择客户端是否可以访问硬件。case AVAuthorizationStatusRestricted: //无权访问媒体类型的硬件case AVAuthorizationStatusDenied: //明确拒绝访问支持客户端媒体类型的硬件。return NO;break;default://可用return YES;break;}
}
swift
import AVFoundation
///相机权限
public class YLPhoneTool: NSObject {///相机权限public class var systemCreame: Bool {get {let status = AVCaptureDevice.authorizationStatus(for: .video)switch status {case .restricted, .denied, .notDetermined:return falsedefault:return true}}}
}
判断是是否开启相册权限
系统说明
typedef NS_ENUM(NSInteger, PHAuthorizationStatus) {PHAuthorizationStatusNotDetermined = 0, // 用户尚未对此应用程序做出选择PHAuthorizationStatusRestricted, // 此应用程序无权访问照片数据。// 用户无法更改此应用程序的状态,可能是由于活动限制 PHAuthorizationStatusDenied, // 用户已明确拒绝此应用程序访问照片数据。PHAuthorizationStatusAuthorized, // 用户已授权此应用程序访问照片数据。PHAuthorizationStatusLimited API_AVAILABLE(ios(14)), // 用户已授权此应用程序访问有限的照片库 iOS 14以上
};
#import <Photos/PHPhotoLibrary.h>+ (BOOL)getPhoto {PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];switch (status) {case PHAuthorizationStatusNotDetermined: //用户尚未对此应用程序做出选择case PHAuthorizationStatusRestricted: //此应用程序无权访问照片数据。case PHAuthorizationStatusDenied: //用户已明确拒绝此应用程序访问照片数据。return NO;break;default: // 用户已授权此应用程序访问照片数据。 或有限的访问权限return YES;break;}
}
swift
public class YLPhoneTool: NSObject { ///相册权限public class var systemAlbum: Bool {get {let status = PHPhotoLibrary.authorizationStatus()switch status {case .notDetermined, .restricted, .denied:return falsedefault:return true}}}
}
是否开启通知权限
typedef NS_ENUM(NSInteger, UNAuthorizationStatus) {// 用户尚未选择应用程序是否可以发布用户通知。UNAuthorizationStatusNotDetermined = 0,// 应用程序无权发布用户通知。UNAuthorizationStatusDenied,//应用程序被授权发布用户通知。UNAuthorizationStatusAuthorized,// 应用程序被授权发布非中断用户通知。UNAuthorizationStatusProvisional API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0)),// 应用程序被临时授权发布通知。仅适用于应用程序剪辑。UNAuthorizationStatusEphemeral API_AVAILABLE(ios(14.0)) API_UNAVAILABLE(macos, watchos, tvos)
} API_AVAILABLE(macos(10.14), ios(10.0), watchos(3.0), tvos(10.0));
oc
//block回调自己写就好,我就不备注了
+ (void)getNotification:(callback)block {[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {if (settings.authorizationStatus == UNAuthorizationStatusAuthorized){block(YES);NSLog(@"有推送权限"); } else {block(NO);NSLog(@"无推送权限,弹窗处理");}}];
}
swift
public class YLPhoneTool: NSObject {
///通知权限public class func systemNoti(isOpen: @escaping (_ open: Bool) -> Void) {UNUserNotificationCenter.current().getNotificationSettings { settings in//有权限if settings.authorizationStatus == .authorized {isOpen(true)} else {isOpen(false)}}}
}
是否开启定位权限
#import <CoreLocation/CoreLocation.h>+ (BOOL)getLocation {//当前状态if ([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) {return YES;}return NO;
}
跳转到APP设置页面
oc
NSURL * appSettingURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];if ([[UIApplication sharedApplication] canOpenURL:appSettingURL]){[[UIApplication sharedApplication] openURL:appSettingURLoptions:@{}completionHandler:nil];}
swift
guard let settingURL = URL(string: UIApplication.openSettingsURLString) else {return}if UIApplication.shared.canOpenURL(settingURL) {UIApplication.shared.open(settingURL,options: [:],completionHandler: nil)}