Macos 如何在OSX项目中以编程方式获得网络服务订单

Macos 如何在OSX项目中以编程方式获得网络服务订单,macos,system-configuration,Macos,System Configuration,Im我的代码我正在尝试使用SCNetworkSetGetServiceOrder获取网络服务订单。如下 Ethernet FireWire Wi-Fi Bluetooth PAN Thunderbolt Bridge 我正在使用下面的代码 -(void)getserviceorder { CFArrayRef interfaces; CFIndex interfaceCount;

Im我的代码我正在尝试使用SCNetworkSetGetServiceOrder获取网络服务订单。如下

Ethernet
FireWire
Wi-Fi
Bluetooth PAN
Thunderbolt Bridge
我正在使用下面的代码

    -(void)getserviceorder
    {
           CFArrayRef          interfaces;
            CFIndex            interfaceCount;
            CFIndex            interfaceIndex;
            CFMutableArrayRef  result;
            CFArrayRef *portArray;
            portArray = NULL;
            result = NULL;
            interfaces = NULL;
                if (SCNetworkInterfaceCopyAll != NULL) {
                interfaces = SCNetworkInterfaceCopyAll();
                interfaceCount = CFArrayGetCount(interfaces);

            for (interfaceIndex = 0; interfaceIndex < interfaceCount;
                 interfaceIndex++) {
                SCNetworkInterfaceRef  thisInterface;
                SCNetworkSetRef set =         CFArrayGetValueAtIndex(interfaces,interfaceIndex);
                assert(thisInterface != NULL);

               NSLog(@"SCNetworkSetGetServiceOrder is %@",SCNetworkSetGetServiceOrder(set));

            }
                CFRelease(interfaces);
}
-(无效)getserviceorder
{
CFArrayRef接口;
CFIndex接口计数;
CFIndex接口索引;
CFMutableArrayRef结果;
CFArrayRef*portArray;
portArray=NULL;
结果=空;
接口=空;
如果(SCNetworkInterfaceCopyAll!=NULL){
interfaces=SCNetworkInterfaceCopyAll();
interfaceCount=CFArrayGetCount(接口);
对于(interfaceIndex=0;interfaceIndex
但是它总是返回null。这是正确的方法还是我如何使用SCNetworkSetGetServiceOrder方法来获取服务订单。作为
SCNetworkSetGetServiceOrder
方法的参数的
(SCNetworkSetRef集)
的值应该是多少。例如,我在哪里可以了解有关此的更多信息:


非常好…有没有关于重新排序网络集的想法,比如先WiFi,然后以太网和其他网卡?尝试使用
SCNetworkSetSetServiceOrder(netset!,newSet)
,但没有成功
import SystemConfiguration

let scpref = SCPreferencesCreate(kCFAllocatorDefault, "iflist" as CFString, nil)

let netset = SCNetworkSetCopyCurrent(scpref!)
let netservs = SCNetworkSetGetServiceOrder(netset!)! as NSArray

for id in netservs {
    print("id \(id)")
    let serv = SCNetworkServiceCopy(scpref!, id as! CFString)!
    if SCNetworkServiceGetEnabled(serv) {
        if let interface = SCNetworkServiceGetInterface(serv) {
            let serviceName = SCNetworkServiceGetName(serv)
            print(serviceName as! String)
        }
    }
}