現在のユーザ名(コンソールで使用されるもの)を取得するには、System Configuration Framework を使用する。
#import <SystemConfiguration/SystemConfiguration.h>
NSString *GetUserName() {
NSString *ret = nil;
CFStringRef userName = SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL);
if (userName) {
ret = NSString stringWithString:(NSString *) userName;
CFRelease(userName);
}
return ret;
}
プロジェクトに SystemConfiguration.framework を加えるのを忘れずに。
コメントを書く