有没有办法像我们在 iOS 中那样在 macOS 下将用户发送到应用程序的隐私设置?

rma*_*ddy 2 ios mac-catalyst

与许多应用程序一样,如果某个隐私权限已被禁用,我的 iOS 应用程序为用户提供了打开应用程序设置页面的机会。

在 iOS 中,使用特殊的UIApplicationOpenSettingsURLString/ openSettingsURLStringURL 会将用户带到设置应用程序的应用程序特定页面。除了应用程序提供的 Settings.bundle 中的任何设置设置(如果有)之外,用户还可以在那里看到应用程序使用的各种隐私设置。

在 iOS 应用程序的 Mac Catalyst 端口上工作时,这并没有像预期的那样工作。特殊设置 URL 的相同用法显示用户在单击“首选项...”菜单时看到的相同首选项窗格。这只是应用程序的 Settings.bundle 提供的内容。该应用程序的隐私设置不像在 iOS 中那样显示。

我可以在 macOS 设置应用程序中查看我的应用程序的隐私设置,方法是单击“安全和隐私”,然后单击“隐私”选项卡,然后单击左侧列表中的相应项目,例如“联系人”或“照片”。但这些设置不按应用分组。

有没有办法让 iOS 应用程序的 macOS 版本在一个地方显示各种隐私设置,就像在 iOS 上运行时一样?如果没有,是否至少有一种方法可以在 macOS 中直接启动“设置”应用程序并显示“隐私”窗格?

rma*_*ddy 5

这与你在 iOS 中得到的并不完全相同,但它与我认为你能得到的一样接近。基于上发现的信息这个答案可可按钮打开系统首选项页我更新了我的代码如下:

目标-C:

    NSString *url;
#if TARGET_OS_MACCATALYST
    url = @"x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars"; // Update as needed
#else
    url = UIApplicationOpenSettingsURLString;
#endif
    [UIApplication.sharedApplication openURL:[NSURL URLWithString:url] options:@{} completionHandler:nil];
Run Code Online (Sandbox Code Playgroud)

迅速:

let url: String
#if targetEnvironment(macCatalyst)
url = "x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars" // Update as needed
#else
url = UIApplication.openSettingsURLString
#endif
UIApplication.shared.open(URL(string: url)!)
Run Code Online (Sandbox Code Playgroud)

以下是一些可能的隐私设置的 URL:

隐私 x-apple.systempreferences:com.apple.preference.security?Privacy
隐私-照片 x-apple.systempreferences:com.apple.preference.security?Privacy_Photos
隐私-相机 x-apple.systempreferences:com.apple.preference.security?Privacy_Camera
隐私-麦克风 x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone
隐私位置 x-apple.systempreferences:com.apple.preference.security?Privacy_LocationServices
Privacy-Contacts x-apple.systempreferences:com.apple.preference.security?Privacy_Contacts
隐私日历 x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars
隐私提醒 x-apple.systempreferences:com.apple.preference.security?Privacy_Reminders

注意:虽然这在开发中有效,但我还不确定这是否会被 App Store 批准。