コンピュータ名の取得

Cocoaに関するヌマタメモ
2008年11月29日 22:48

システム環境設定の「共有」で設定したコンピュータ名を取得するには、System Configuration Framework を使用する。

#import <SystemConfiguration/SystemConfiguration.h>

NSString *GetComputerName() {
    NSString *ret = nil;
    CFStringRef computerName = SCDynamicStoreCopyComputerName(NULLNULL);
    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

コメントを書く


トラックバックはありません。

トラックバックURL: http://numata.designed.jp/mt-tb.cgi/54