macOS開発-NSMicrophoneUsageDescription



Macos Development Nsmicrophoneusagedescription



記事のディレクトリ


Macを10.14にアップグレードした後、プロジェクトプロンプトを実行します。

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data.

NSMicrophoneUsageDescriptionキーと対応する説明をInfo.plistに追加する必要があります。これは、カメラの権限に関するiOSアプリケーションに似ています。
これは、macOS10.14のプライバシー管理がより厳格であるためです。詳細については、wwdcを参照してください。 https://developer.apple.com/videos/play/wwdc2018/702/?time=1049




次に、info.plistの設定に加えて、マイクのアクセス許可が呼び出されているかどうかも確認する必要があります。

- (BOOL)isValidToVisitMicroPhone{ NSString *version = [SystemTools getSystemVersion] if (version.floatValue <10.14) { return YES } NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio] // NSLog(@'videoDevices : %@',videoDevices) __block BOOL bCanRecord = YES AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio] NSLog(@'status : %d',status) switch (status) { case AVAuthorizationStatusNotDetermined:{ // The license dialog did not appear, initiate a license [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) { if (granted) { //First user acceptance NSLog(@'-- granted') }else{ / / User refused NSLog(@'-- not granted') } }] break } case AVAuthorizationStatusAuthorized:{ // The authorization has been turned on and can continue NSLog(@'-- Authorized') bCanRecord = YES break } case AVAuthorizationStatusDenied:{ NSLog(@'-- Denied') bCanRecord = NO break } case AVAuthorizationStatusRestricted:{ NSLog(@'-- Restricted') bCanRecord = NO break } default: break } return bCanRecord }

呼び出されない場合は、プライバシーパネルにジャンプできます



- (void)openSetting{ NSString *urlString = @'x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone' [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]] }