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



与许多应用程序一样,我的iOS应用程序为用户提供了在禁用特定隐私权限的情况下打开应用程序设置页面的机会。

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

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

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

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

这与你在iOS中获得的并不完全相同,但它与我认为你可以得到的一样接近。根据在此 Cocoa 答案按钮上找到的信息,打开系统偏好设置页面,我更新了我的代码,如下所示:

目标-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];

迅速:

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)!)

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

隐私 x-apple.systempreferences:com.apple.ppreferences.security?隐私 Privacy-Photos x-apple.systempreferences:com.apple.ppreferences.security?Privacy_Photos Privacy-Camera x-apple.systempreferences:com.apple.preference.security?Privacy_Camera Privacy-Microphone x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone Privacy-Location x-apple.systempreferences:com.apple.ppreferences.security?Privacy_LocationServices Privacy-Contacts x-apple.systempreferences:com.apple.ppreferences.security?Privacy_Contacts Privacy-Calendars x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars 隐私提醒 x-apple.systempreferences:com.apple.ppreferences.security?Privacy_Reminders

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

最新更新