Modify SCPreferences persistent storage: Invalid Argument

守給你的承諾、 提交于 2019-12-25 02:24:46

问题


Currently trying to modify /Library/Preferences/com.apple.Bluetooth.plist in order to programmatically remove Bluetooth devices and running into an error.

First of all, when SCPreferencesSetValue is called, System Configuration says

Error Domain=com.apple.SystemConfiguration Code=0 "Success!" UserInfo={NSDescription=Success!}

However, when I try to SCPreferencesCommitChanges, the framework tells me

Error Domain=com.apple.SystemConfiguration Code=1002 "Invalid argument" UserInfo={NSDescription=Invalid argument}

I don't understand how setting a value succeeds but committing a value with a regular preferences object fails... Any help would be appreciated. Thank you!


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())")
}

来源:https://stackoverflow.com/questions/55764449/modify-scpreferences-persistent-storage-invalid-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!