一台计算机可以同时绑定多个网络帐户服务器。要列出它们,您可以通过创建 ODSession 并列出所有已注册的节点来使用 OpenDirectory 框架。
#import <OpenDirectory/OpenDirectory.h>
...
ODSession *mySession = [ODSession defaultSession];
NSError *err;
NSArray *nodeNames = [mySession nodeNamesAndReturnError:&err];
NSLog(@"nodeNames=%@", nodeNames);
我绑定到 Mac-mini.local OpenDirectory Server,并且输出如下:
nodeNames=(
"/Contacts",
"/LDAPv3/Mac-mini.local",
"/Local/Default",
"/Search"
)
要获取有关已注册节点的更多信息,只需从 nodeNames 数组中的节点名称创建一个 ODNode 实例,并使用它来查询该节点。
ODNode *node = [[ODNode alloc] initWithSession:mySession name:@"/LDAPv3/Mac-mini.local" error:&err];
或者,您也可以直接创建顶级节点的 ODNode 实例,例如 /LDAPv3 节点,然后只询问它的子节点,如下所示:
ODNode *node = [[ODNode alloc] initWithSession:mySession name:@"/LDAPv3" error:&error];
NSArray *subnodes = [node subnodeNamesAndReturnError:&err];
NSLog(@"subnodes=%@", subnodes);
这给了我这个输出:
subnodes=(
"/LDAPv3/Mac-mini.local"
)
注意:还有-unreachableSubnodeNamesAndReturnError:
如果您需要有关此框架的更多信息,可以找到文档here