当前正在尝试修改/Library/Preferences/com.apple.Bluetooth.plist
,以便以编程方式删除Bluetooth设备并出现错误。
首先,当调用SCPreferencesSetValue
时,系统配置会显示
错误Domain = com.apple.SystemConfiguration代码= 0“成功!” UserInfo = {NSDescription =成功!}
但是,当我尝试SCPreferencesCommitChanges
时,框架会告诉我
错误Domain = com.apple.SystemConfiguration代码= 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())")
}