システム環境設定の「共有」で設定したコンピュータ名を取得するには、System Configuration Framework を使用する。
#import <SystemConfiguration/SystemConfiguration.h>
NSString *GetComputerName() {
NSString *ret = nil;
CFStringRef computerName = SCDynamicStoreCopyComputerName(NULL, NULL);
if (computerName != NULL) {
ret = NSString stringWithString:(NSString *)computerName;
CFRelease(computerName);
}
return ret;
}
プロジェクトに SystemConfiguration.framework を加えるのを忘れずに。
参考資料
http://developer.apple.com/qa/qa2001/qa1078.html file:///System/Library/Frameworks/SystemConfiguration.framework/Versions/A/Headers/SCDynamicStoreCopySpecific.h
コメントを書く