1
스위프트를 사용하여 CPU 온도를 알아야하지만 this을 제외한 모든 정보를 찾을 수 없습니다.macOS. 프로그래밍 방식으로 CPU 온도를 얻는 방법
IOKit.framework를 사용해야한다고 생각하지만 다시 그것에 대한 정보는 없습니다.
스위프트를 사용하여 CPU 온도를 알아야하지만 this을 제외한 모든 정보를 찾을 수 없습니다.macOS. 프로그래밍 방식으로 CPU 온도를 얻는 방법
IOKit.framework를 사용해야한다고 생각하지만 다시 그것에 대한 정보는 없습니다.
https://github.com/lavoiesl/osx-cpu-temp/blob/master/smc.c을 사용하면 효과가 있습니다.
double calculate()
{
SMCOpen();
double temperature = SMCGetTemperature(SMC_KEY_CPU_TEMP);
SMCClose();
temperature = convertToFahrenheit(temperature);
return temperature;
}
이 ObjC 래퍼를 쓰기 :
#import "SMCObjC.h"
#import "smc.h"
@implementation SMCObjC
+(double)calculateTemp {
return calculate();
}
@end
이 스위프트 브리지 헤더에 헤더를 추가
단순화 main()
다른 일에 : 당신은 몇 가지를해야한다. 응용 프로그램이 샌드 박스되면
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "SMCObjC.h"
는 AppleSMC에 대한 보안 면제를 추가 스위프트에서
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.temporary-exception.sbpl</key>
<array>
<string>(allow iokit-open)</string>
<string>(allow iokit-set-properties (iokit-property "AppleSMC"))</string>
<string>(allow mach-lookup (global-name "com.apple.AssetCacheLocatorService"))</string>
</array>
</dict>
</plist>
전화를.
https://www.dropbox.com/sh/lpe9bm08s2ynoob/AAA-N_br7aqRxJRks53FYK0fa?dl=0
그것은 작동합니다
여기 내 샘플 프로젝트입니다! 고맙습니다 –