目前正在尝试修改/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())")
}