产品 / 解决方案
平台 / 框架

如何解决 macOS 权限问题?

产品 / 插件:屏幕共享

平台 / 框架:macOS

更新时间:2022-11-16 18:05


1. 如何检查电脑是否开启应用的截取屏幕权限和辅助功能?

请打开 macOS 电脑的“系统偏好设置”,找到“安全性与隐私”选项,切换到“隐私”选项卡,确认以下权限是否开启:

/Pics/macOS/ScreenSharing/CommonProblems/screenSharing_Problems_macOS_1.png
/Pics/macOS/ScreenSharing/CommonProblems/screenSharing_Problems_macOS_2.png

2. 为什么打开了权限,还是无法截取图片或者报错?

在 macOS 电脑的“设置”中看到的状态,并不是应用真实的状态,建议使用代码判断权限是否开启(请参考下文的“4. 如何判断系统权限?”)。

如果已经开启权限,请先关闭后,再次打开重试。

3. 如何跳转到系统设置权限弹窗?

请参考此网址设置 “系统相关 URL”:MacOS System Preference Links

4. 如何判断系统权限?

  • 辅助功能权限

    可以通过调用以下 SDK 的内部接口确认权限。

    1. 1
    SCREENCAPTURE_API bool zego_windowthumbnail_window_checkStatus(ZegoWindowHandle handle);
  • 屏幕录制权限

    macOS 10.15 版本后的系统以后需要开启此权限。SDK 对此权限功能没有封装,需要用户自行实现。 请参考以下代码:

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    bool ZegoSDKEngineMacUtils::checkScreenCapturePermission() { if (QSysInfo::macVersion() < 14) { return true; } if (@available(macOS 10.15, *)) { CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); NSUInteger numberOfWindows = CFArrayGetCount(windowList); NSUInteger numberOfWindowsWithInfoGet = 0; for (int idx = 0; idx < numberOfWindows; idx++) { NSDictionary *windowInfo = (NSDictionary *)CFArrayGetValueAtIndex(windowList, idx); NSString *windowName = windowInfo[(id)kCGWindowName]; NSNumber* sharingType = windowInfo[(id)kCGWindowSharingState]; if (windowName || kCGWindowSharingNone != sharingType.intValue) { numberOfWindowsWithInfoGet++; } else { NSNumber* pid = windowInfo[(id)kCGWindowOwnerPID]; NSString* appName = windowInfo[(id)kCGWindowOwnerName]; // NSLog(@"windowInfo get Fail pid:%lu appName:%@", pid.integerValue, appName); } } CFRelease(windowList); if (numberOfWindows == numberOfWindowsWithInfoGet) { return true; } else { return false; } } return true; }
鼠标划词,快速反馈
鼠标选中文档内容,快速反馈问题
不再提示