I’m not familiar with objective-c, so it is hard for me to understand it and convert it to c++.
The objective-c code as follows, it will get the iOS system proxy. Could you help me to convert it to c++?
NSDictionary *proxySettings = NSMakeCollectable([(NSDictionary *)CFNetworkCopySystemProxySettings() autorelease]);
NSArray *proxies = NSMakeCollectable([(NSArray *)CFNetworkCopyProxiesForURL((CFURLRef)[NSURL URLWithString:@"http://www.google.com"], (CFDictionaryRef)proxySettings) autorelease]);
NSDictionary *settings = [proxies objectAtIndex:0];
NSLog(@"host=%@", [settings objectForKey:(NSString *)kCFProxyHostNameKey]);
NSLog(@"port=%@", [settings objectForKey:(NSString *)kCFProxyPortNumberKey]);
NSLog(@"type=%@", [settings objectForKey:(NSString *)kCFProxyTypeKey]);
The code example you found is already using C APIs (CFNetworkCopySystemProxySettings, CFNetworkCopyProxiesForURL), and is then going to some additional work to convert the results to something more friendly for an Objective-C program (for example, calling NSMakeCollectable to enable Objective-C garbage collection).
It may help you to understand this if you know that the “CF*” calls are “Core Foundation” API, which is callable from C (or C++), and “NS*” things are Objective-C classes/methods. So your task is to re-cast the code using just the Core Foundation calls & datatypes. For example, CFDictionary and NSDictionary are interchangeable (“toll-free bridged”, in Apple parlance), so you can handle the dictionary from a C/C++ program by using the CFDictionary API instead of NSDictionary.
To understand how this is working (instead of just asking someone else to translate it for you), you will want to research functions like:
CFNetworkCopySystemProxySettings
CFURLCreateWithString
CFNetworkCopyProxiesForURL
CFDictionaryGetValue
You’ll also need a basic understanding of Core Foundation memory management rules