SwiftUI打开Mac系统偏好面板方法,打开指定偏好设置面板指定设置
文章摘要
HeoGPT
这篇文章介绍了在SwiftUI中打开Mac系统偏好面板的方法,通过使用URL Scheme来访问控制面板,可以打开指定偏好设置面板和指定设置。文章列举了一些控制面板的Bundle Identifier和锚点名称,方便开发者快速定位需要打开的面板。
此内容根据文章生成,并经过人工审核,仅用于文章内容的解释与总结
投诉mac程序经常会用到要求用户更改安全设置、隐私设置等问题的情况,所以需要弹出系统设置界面让不精通mac操作的用户能够轻而易举的修改偏好设置。
使用URL Scheme
首先我们想到的就是使用urlScheme来打开窗口。在swiftUI下使用urlScheme非常容易。
我们需要在结构体中引用
1 | @Environment(\.openURL) var openURL |
之后我们来打开url
1 | openURL(URL(string: "https://blog.zhheo.com/")!) |
我们就完成了一个打开网页的操作。将网页url更换成urlScheme同样可用。
那么需要更改成什么url呢?
URL Scheme 格式
部分控制面板支持通过 URL Scheme 进行访问。在各个控制面板对应的 .prefpane
文件里的 Info.plist
中,如果有下面这一键值对,则表示这个面板支持 URL Scheme:
1 | <key>NSPrefPaneAllowsXAppleSystemPreferencesURLScheme</key> |
控制面板的 URL Scheme 格式是 x-apple.systempreferences:
前缀加上面板的 Bundle Identifier:
有些面板支持锚点,可以在 URL Scheme 后面加入锚点名称来访问控制面板的某个区域:
Siri Pane
1 | com.apple.preference.speech |
Notifications Pane
1 | com.apple.preference.notifications |
Accessibility Pane
1 | com.apple.preference.universalaccess |
- Display
com.apple.preference.universalaccess?Seeing_Display
- Zoom
com.apple.preference.universalaccess?Seeing_Zoom
- VoiceOver
com.apple.preference.universalaccess?Seeing_VoiceOver
- Descriptions
com.apple.preference.universalaccess?Media_Descriptions
- Captions
com.apple.preference.universalaccess?Captioning
- Audio
com.apple.preference.universalaccess?Hearing
- Keyboard
com.apple.preference.universalaccess?Keyboard
- Mouse & Trackpad
com.apple.preference.universalaccess?Mouse
- Switch Control
com.apple.preference.universalaccess?Switch
- Dictation
com.apple.preference.universalaccess?SpeakableItems
Screen Time
1 | com.apple.preference.screentime |
Main Tabs
1 | com.apple.preference.security |
- General
com.apple.preference.security?General
- Advanced
com.apple.preference.security?Advanced
- FileVault
com.apple.preference.security?FDE
- Firewall
com.apple.preference.security?Firewall
- Privacy Main
com.apple.preference.security?Privacy
Privacy Anchors
- Location Services
com.apple.preference.security?Privacy_LocationServices
- Contacts
com.apple.preference.security?Privacy_Contacts
- Calendars
com.apple.preference.security?Privacy_Calendars
- Reminders
com.apple.preference.security?Privacy_Reminders
- Photos
com.apple.preference.security?Privacy_Photos
- Camera
com.apple.preference.security?Privacy_Camera
- Microphone
com.apple.preference.security?Privacy_Microphone
- Speech Recognition
com.apple.preference.security?Privacy_SpeechRecognition
- Accessibility
com.apple.preference.security?Privacy_Accessibility
- Input Monitoring Not Available
- Full Disk Access
com.apple.preference.security?Privacy_AllFiles
- Files and Folders Not Available
- Screen Recording Not Available
- Automation
com.apple.preference.security?Privacy_Automation
- Analytics and Improvements
com.apple.preference.security?Privacy_Diagnostics
- Advertising
com.apple.preference.security?Privacy_Advertising
Keyboard Pane
- Dictation
com.apple.preference.speech?Dictation
Sharing Preference Pane
1 | com.apple.preferences.sharing |
- Screen Sharing
com.apple.preferences.sharing?Services_ScreenSharing
- File Sharing
com.apple.preferences.sharing?Services_PersonalFileSharing
- Printer Sharing
com.apple.preferences.sharing?Services_PrinterSharing
- Remote Login
com.apple.preferences.sharing?Services_RemoteLogin
- Remote Management
com.apple.preferences.sharing?Services_ARDService
- Remote Apple Events
com.apple.preferences.sharing?Services_RemoteAppleEvent
- Internet Sharing
com.apple.preferences.sharing?Internet
- Bluetooth Sharing
com.apple.preferences.sharing?Services_BluetoothSharing
参考文档
- 感谢你赐予我前进的力量
打赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 张洪Heo
评论
生成评论
匿名评论
违规举报
✅ 你无需删除空行,直接评论以获取最佳展示效果