Xcode運(yùn)行真機(jī)開(kāi)啟硬件支持權(quán)限設(shè)置
-
打開(kāi)項(xiàng)目中的info.plist文件進(jìn)行編輯
> 其中一個(gè)
<key>********</key>
<string>******</string>
> 為一個(gè)組合
-
設(shè)置代碼如下:
<!-- 相冊(cè) --> <key>NSPhotoLibraryUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)相冊(cè)</string> <!-- 相機(jī) --> <key>NSCameraUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)相機(jī)</string> <!-- 麥克風(fēng) --> <key>NSMicrophoneUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)麥克風(fēng)</string> <!-- 位置 --> <key>NSLocationUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)位置</string> <!-- 在使用期間訪問(wèn)位置 --> <key>NSLocationWhenInUseUsageDescription</key> <string>App需要您的同意,才能在使用期間訪問(wèn)位置</string> <!-- 始終訪問(wèn)位置 --> <key>NSLocationAlwaysUsageDescription</key> <string>App需要您的同意,才能始終訪問(wèn)位置</string> <!-- 日歷 --> <key>NSCalendarsUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)日歷</string> <!-- 提醒事項(xiàng) --> <key>NSRemindersUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)提醒事項(xiàng)</string> <!-- 運(yùn)動(dòng)與健身 --> <key>NSMotionUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)運(yùn)動(dòng)與健身</string> <!-- 健康更新 --> <key>NSHealthUpdateUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)健康更新 </string> <!-- 健康分享 --> <key>NSHealthShareUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)健康分享</string> <!-- 藍(lán)牙 --> <key>NSBluetoothPeripheralUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)藍(lán)牙</string> <!-- 媒體資料庫(kù) --> <key>NSAppleMusicUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)媒體資料庫(kù)</string>
-
調(diào)用代碼如下:
#import<AVFoundation/AVCaptureDevice.h> #import <AVFoundation/AVMediaFormat.h> #import<AssetsLibrary/AssetsLibrary.h> #import<CoreLocation/CoreLocation.h> //相機(jī)權(quán)限 AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo]; if (authStatus ==AVAuthorizationStatusRestricted ||//此應(yīng)用程序沒(méi)有被授權(quán)訪問(wèn)的照片數(shù)據(jù)那婉。可能是家長(zhǎng)控制權(quán)限 authStatus ==AVAuthorizationStatusDenied) //用戶(hù)已經(jīng)明確否認(rèn)了這一照片數(shù)據(jù)的應(yīng)用程序訪問(wèn) { // 無(wú)權(quán)限 引導(dǎo)去開(kāi)啟 NSURL *url = [NSURLURLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplicationsharedApplication]canOpenURL:url]) { [[UIApplicationsharedApplication]openURL:url]; } } //相冊(cè)權(quán)限 ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus]; if (author ==kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){ //無(wú)權(quán)限 引導(dǎo)去開(kāi)啟 NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; } }