2021年3月3日星期三

Swift - SCPreferencesSetValue - Cannot convert value of type String to expected argument CFString



I wrote some code on MACOS to make my App and setting up on my Proxy Server



I'm working with SCPreferencesSetValue on my editor (XCODE).

The error of XCODE is: Cannot convert value of type String to expected argument CFString

SCPreferencesSetValue(pref as SCPreferences, "/\(kSCPrefNetworkServices)/\(key)/\(kSCEntNetProxies)/\(kCFNetworkProxiesSOCKSEnable)" as CFString, "1" as CFNumber);  

where key is a variable with the hardware code

[something like that: E5924237-6C90-48D2-B78B-4D10XXXXXXXX]

The assurde is that if I change all the dictionary in this way using the path, it works:

var proxies = [NSObject: AnyObject]()  proxies[kCFNetworkProxiesSOCKSEnable] = 1 as NSNumber  proxies[kCFNetworkProxiesSOCKSProxy] = "127.0.0.1" as AnyObject?  proxies[kCFNetworkProxiesSOCKSPort] = 8888 as NSNumber  proxies[kCFNetworkProxiesExcludeSimpleHostnames] = 1 as NSNumber    SCPreferencesPathSetValue(pref, "/\(kSCPrefNetworkServices)/\(key)/\(kSCEntNetProxies)" as CFString, proxies as CFDictionary)  

but if i want to change only one value i don't know why but BIG ERROR and not works. And i'll do this.

Conclusion:

If i use the fist command

SCPreferencesSetValue(pref as SCPreferences, "/\(kSCPrefNetworkServices)/\(key)/\(kSCEntNetProxies)/\(kCFNetworkProxiesSOCKSEnable)" as CFString, "1" as CFNumber);

the key doesn't go in the dictionary in the system preferences and it will go away in the system preferences (at the root of the system preferences) in a external value made only by [key] and [string].

How can i do it? I wanna change only kCFNetworkProxiesExcludeSimpleHostnames.

What i've to do?

https://stackoverflow.com/questions/66450020/swift-scpreferencessetvalue-cannot-convert-value-of-type-string-to-expected March 03, 2021 at 10:43AM

没有评论:

发表评论