swift - 修改 SCPreferences 持久存储:无效参数
问题描述
目前正在尝试修改/Library/Preferences/com.apple.Bluetooth.plist
以便以编程方式删除蓝牙设备并遇到错误。
首先,当SCPreferencesSetValue
被调用时,系统配置说
错误域=com.apple.SystemConfiguration 代码=0“成功!” UserInfo={NSDescription=成功!}
但是,当我尝试时SCPreferencesCommitChanges
,框架告诉我
错误域=com.apple.SystemConfiguration Code=1002 “无效参数” UserInfo={NSDescription=无效参数}
我不明白设置值如何成功,但使用常规首选项对象提交值失败......任何帮助将不胜感激。谢谢!
var authItem = AuthorizationItem(name: kAuthorizationRuleIsAdmin, valueLength: 0, value: nil, flags: 0)
var authRights = AuthorizationRights(count: 1, items: &authItem)
let flags : AuthorizationFlags = [.interactionAllowed, .extendRights, .preAuthorize, .extendRights]
let osStatus = AuthorizationCopyRights(self.authRef!, &authRights, nil, flags, nil)
let preferences = SCPreferencesCreateWithAuthorization(kCFAllocatorDefault, "defaults" as CFString, "/Library/Preferences/com.apple.Bluetooth.plist" as CFString, authRef)
if !(SCPreferencesSetValue(preferences!, "PairedDevices" as CFString, paired as CFPropertyList)) {
return false
}
print("Set Value: \(SCCopyLastError())")
let ok = SCPreferencesCommitChanges(preferences!)
if !ok {
print("Commit Changes: \(SCCopyLastError())")
}
解决方案
推荐阅读
- gitlab - 美人鱼类图只会变宽,忽略方向
- function - 如何在pyret中编写递归乘法函数
- c++ - 为什么输入验证会返回部分输入而不是将整个输入声明为错误
- xml - XML 模式 - 名称空间选择歧义
- c# - 从 D365 dataverse JSON 中检索值的最简单方法?
- java - AuthenticationManager 的扩展点
- flutter - Flutter:获取过去在 Android 上的购买记录
- python - 使用 scikit wine 数据集制作 sns.pairplot
- android - 以编程方式创建自定义 ProgressBar 可绘制对象
- javascript - 使用 Axios 时响应不一致(Postman vs VSCode)