macOS development - 10.15 Screen Recording screen recording and authorized Jump


method

1, the authority to determine

Under the SIP (under normal circumstances):


- (BOOL)canRecord{
    CGDisplayStreamRef stream = CGDisplayStreamCreate(CGMainDisplayID() , 1, 1, kCVPixelFormatType_32ABGR, nil, ^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef  _Nullable frameSurface, CGDisplayStreamUpdateRef  _Nullable updateRef) {
        
    });
    
    BOOL canRecord = stream != NULL;
    if (stream) {
        CFRelease(stream);
    }
    
    NSLog(@"canRecord : %ld",canRecord);
    return canRecord;
}

If insensitive, try to use tccutil reset All com.xx.xxto try to clean up the authorization.


In the case of closing the SIP, can be obtained by reading all authorized tcc.data.
If it returns 1, the authorized representative of success; return 0 or nothing to return to, on behalf of is not authorized. In particular there is no user operation, the need for further discrimination.

$ sqlite3 /Library/Application\ Support/com.apple.TCC/TCC.db "SELECT  allowed  from access WHERE client='com.ms.AuthDemo' AND service='kTCCServiceScreenCapture';"

2. Application for authorization

Call the screenshot method, will be transferred from the application permissions window system;
but here, whether or not authorization is successful, we are able screenshots.
Therefore, this method is not suitable to do right judgment.

- (void)showScreenRecordingPrompt{
  
  /* macos 10.14 and lower do not require screen recording permission to get window titles */
  if(@available(macos 10.15, *)) {
    /*
     To minimize the intrusion just make a 1px image of the upper left corner
     This way there is no real possibilty to access any private data
     */
    CGImageRef c = CGWindowListCreateImage(
                                                    CGRectMake(0, 0, 1, 1),
                                                    kCGWindowListOptionOnScreenOnly,
                                                    kCGNullWindowID,
                                                    kCGWindowImageDefault);
  
      CFRelease(screenshot);

}


3, jump privacy panel

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

Exploration experience

1, about 10.15 permissions

It suggested that the main machine currently do not upgrade to 10.15. However, after the upgrade, only to find non-main machine is so important. Encounter various problems when sincerely feel really SB.
But for this fall compatible system, which is essential. 10.14 permission to start more and more strict, 10.15 has added some authority.

If you just open the panel, it is very easy. But requires precise open the corresponding tab is more user-friendly. How to get these Privacy field it? The first thing I think of is that the system language into English. We can see the following effect:

Sample Sample

2, on the privacy panel Jump

Microphone This jump is very direct, address access Privacy_Microphoneto:
@"x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone";

So Screen Recordingwhat? The following natural conjecture

  • Privacy_ScreenRecording
  • Privacy_Screen_Recording
  • Privacy_Screen\n Recording

Of course, it is null and void;

So how do you get the corresponding permission to name it?


3, get preferences plist information

There is such a plist file, whether to save the configuration information we do?
~/Library/Preferences/com.apple.systempreferences.plist

Apparently not.

By checking / cancellation of part of rights, no data is stored here. Here are just save this using panel data. Such as:

  • SecurityPrefTab On behalf of the security of the newly selected tab
  • com.apple.SecurityPref.Privacy.LastSourceSelected Privacy representatives selected in the first few item.

4、tcc

Before - "macOS Development NSMicrophoneUsageDescription (10.14 mojave rights issue" https://blog.csdn.net/lovechris00/article/details/83542730 wrote, if you like to clean up the authorization record, need to use tccutil command (and still do not. tcc figure out what the acronym, I know of a small partner to leave a message). so if there is relevant information tcc in it?
man tccutiland I did not give similar information, feel tccutil just to clean up, and can not be added.


But indeed tcc database for managing authorization data, the following two db management authorization information:
~/Library/Application Support/com.apple.TCC/TCC.db
/Library/Application Support/com.apple.TCC/TCC.db

Here Insert Picture Description


A can of CRUD tccutil
https://github.com/jacobsalmela/tccutil


5, using AppleScript get preference pane information

https://apple.stackexchange.com/questions/361045/open-system-preferences-privacy-full-disk-access-with-url
StackOverflow above method using AppleScript:

tell application "System Preferences" to get name of anchors of current pane

I tried, and she saw some familiar words:
but the drawback is that the data is incomplete.

Here Insert Picture Description


6、OS X System Preference Links

Mac on the "Privacy" Preferences
https://support.apple.com/zh-cn/guide/mac-help/mh32356/mac


Encountered such a site, gives some privacy fields:
https://macosxautomation.com/system-prefs-links.html

https://stackoverflow.com/questions/6652598/cocoa-button-opens-a-system-preference-page


Accessibility Preference Pane

Main x-apple.systempreferences:com.apple.preference.universalaccess
Display Seeing_Display
Zoom Seeing_Zoom
VoiceOver Seeing_VoiceOver
Descriptions Media_Descriptions
Captions Captioning
Audio Hearing
Keyboard Keyboard
Mouse & Trackpad Mouse
Switch Control Switch
Dictation Shpeakbleitems

Security & Privacy Preference Pane

Main x-apple.systempreferences:com.apple.preference.security
General General
FileVault FDE
Firewall Firewall
Advanced Advanced
Privacy Privacy
Privacy-Camera Privacy_Camera
Privacy-Microphone Privacy_Microphone
Automation Privacy_Automation
AllFiles Privacy_AllFiles
Accessibility Privacy_Accessibility
Assistive Privacy_Assistive
Location Services Privacy_LocationServices
SystemServices Privacy_SystemServices
Advertising Privacy_Advertising
Contacts Privacy_Contacts
Diagnostics & Usage Privacy_Diagnostics
Calendars Privacy_Calendars
Reminders Privacy_Reminders
Facebook Privacy_Facebook
LinkedIn Privacy_LinkedIn
Twitter Privacy_Twitter
Weibo Privacy_Weibo
Tencent Weibo Privacy_TencentWeibo

Catalina macOS 10.15:

ScreenCapture/Screen Recording Privacy_ScreenCapture
DevTools Privacy_DevTools
InputMonitoring Privacy_ListenEvent
DesktopFolder Privacy_DesktopFolder
DocumentsFolder Privacy_DocumentsFolder
DownloadsFolder Privacy_DownloadsFolder
NetworkVolume Privacy_NetworkVolume
RemovableVolume Privacy_RemovableVolume
SpeechRecognition Privacy_SpeechRecognition

Dictation & Speech Preference Pane

Main x-apple.systempreferences:com.apple.preference.speech
Dictation Dictation
Text to Speech TTS

Sharing Preference Pane

Main x-apple.systempreferences:com.apple.preferences.sharing
Screen Sharing Services_ScreenSharing
File Sharing Services_PersonalFileSharing
Printer Sharing Services_PrinterSharing
Remote Login Services_RemoteLogin
Remote Management Services_ARDService
Remote Apple Events Services_RemoteAppleEvent
Internet Sharing Internet
Bluetooth Sharing Services_BluetoothSharing
Published 164 original articles · won praise 162 · Views 650,000 +

Guess you like

Origin blog.csdn.net/lovechris00/article/details/96979960