文章目录
方法
1、权限判断
在 SIP 下(正常情况下):
- (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; }
如果不灵敏,试试用 tccutil reset All com.xx.xx
清理授权试试。
$ sqlite3 /Library/Application\ Support/com.apple.TCC/TCC.db "SELECT allowed from access WHERE client='com.ms.AuthDemo' AND service='kTCCServiceScreenCapture';"
2、申请授权
调用截屏方法,会调起系统的申请权限窗口;
但这里无论是否授权成功,都能够截屏。
所以这个方法不适宜做权限判断。
- (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、隐私面板跳转
- (void)openSetting{
NSString *urlString = @"x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture"; [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]]; }
探索经历
1、关于 10.15 权限
如果只是打开面板,是非常容易的。但需要精准打开对应的tab才更方便用户使用。如何获取这些Privacy 字段呢? 首先我想到的是,把系统语言转化为英文。可以看到如下效果:
2、关于隐私面板跳转
Microphone 这种跳转是非常直接的,地址接 Privacy_Microphone
即可:
@"x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone";
那么 Screen Recording
呢?自然有以下猜想
Privacy_ScreenRecording
Privacy_Screen_Recording
Privacy_Screen\n Recording
当然,都是无效的;
那么如何获取这个权限对应的名字呢?
3、获取偏好设置plist信息
存在一个这样的 plist 文件,是否保存了我们的配置信息呢?
~/Library/Preferences/com.apple.systempreferences.plist
显然没有。
通过勾选/取消部分权限,数据并没保存在这里。这里只是保存了这个面板的使用数据。如:
SecurityPrefTab
代表在 security 中刚选中的 tabcom.apple.SecurityPref.Privacy.LastSourceSelected
代表在 Privacy 中选中的第几个item。
4、tcc
之前在 《macOS 开发 - NSMicrophoneUsageDescription (10.14 mojave 权限问题》macOS 开发 - 10.15 Screen Recording 屏幕录制 授权及跳转 中写过,如果像清理授权记录,需要用到 tccutil 命令。(现在依然没搞清楚 tcc 是什么的缩写,知道的小伙伴给我留言吧)。那么tcc 中是否有相关信息呢?
man tccutil
中并没有给我类似的信息,感觉 tccutil 只是用来清理,而无法添加。
但 tcc 数据库确是用来管理授权数据的,下面两个db管理了授权信息:
~/Library/Application Support/com.apple.TCC/TCC.db
/Library/Application Support/com.apple.TCC/TCC.db
5、使用 AppleScript 获取偏好设置面板信息
tell application "System Preferences" to get name of anchors of current pane
6、OS X System Preference Links
https://stackoverflow.com/questions//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 | SpeakableItems |
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 |
Privacy_Facebook | |
Privacy_LinkedIn | |
Privacy_Twitter | |
Privacy_Weibo | |
Tencent Weibo | Privacy_TencentWeibo |
macOS Catalina 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 |
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/99774.html