Chinaunix首页 | 论坛 | 博客
  • 博客访问: 538783
  • 博文数量: 78
  • 博客积分: 1913
  • 博客等级: 上尉
  • 技术积分: 829
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-14 21:29
文章分类

全部博文(78)

文章存档

2011年(27)

2010年(26)

2009年(20)

2008年(5)

我的朋友

分类:

2010-12-31 14:49:05

终于有解! 不用dscl命令得到机器上的用户列表的cocoa方法:
代码如下:
#import 
#import

CSIdentityAuthorityRef defaultAuthority = CSGetLocalIdentityAuthority();
CSIdentityClass identityClass = kCSIdentityClassUser;

CSIdentityQueryRef query = CSIdentityQueryCreate(NULL, identityClass, defaultAuthority);

CFErrorRef error = NULL;
CSIdentityQueryExecute(query, 0, &error);

CFArrayRef results = CSIdentityQueryCopyResults(query);

int numResults = CFArrayGetCount(results);

NSMutableArray * users = [NSMutableArray array];
for (int i = 0; i < numResults; ++i) {
   
CSIdentityRef identity = (CSIdentityRef)CFArrayGetValueAtIndex(results, i);

   
CBIdentity * identityObject = [CBIdentity identityWithCSIdentity:identity];
   
[users addObject:identityObject];
}

CFRelease(results);
CFRelease(query);
阅读(963) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~