- Mac App Store 安全
手动将模型标识符映射到图标名称,然后使用例如
[[NSWorkspace sharedWorkspace] iconForFileType:@"com.apple.macbookair"];
或
[NSImage imageNamed:NSImageNameComputer]
如果您需要比 imageNamed 提供的分辨率更高的分辨率,请使用
OSType code = UTGetOSTypeFromString((CFStringRef)CFSTR("root"));
NSImage *computer = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(code)];
“root”字符串来自 IconsCore.h 头文件 (kComputer)。
复制此 plist 以获取标识符(不要从应用沙箱访问它)
/System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/English.lproj/SIMachineAttributes.plist
- Mac App Store 不安全
将私有框架 SPSupport.Framework 与您的二进制文件链接
添加 FrameWork 搜索路径变量
$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks
将以下接口添加到您的项目中
#import <Cocoa/Cocoa.h>
@interface SPDocument : NSDocument
- (NSImage *)modelIcon;
- (id)computerName;
- (id)serialNumber;
- (id)modelName;
@end
调用你的代码:
SPDocument *document = [[SPDocument alloc] init];
NSImage *icon = [document modelIcon];
- 最艰难的方式
用这个私有函数弄清楚CoreFoundation跳舞(这个代码是插图,找到正确的类型,参数数量并正确释放)
output = _LSCreateDeviceTypeIdentifierWithModelCode((CFStringRef)@"MacBookPro6,2");
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType: output];
编辑:
我刚刚意识到您需要选项编号 1,3(给定型号的图标)。 GL 与此作斗争。
EDIT2
增加了方法3。更改顺序并添加到编号 1 下。
EDIT3
彩色版本的新尿路感染
com.apple.macbook-视网膜-银
com.apple.device-model-code
MacBook8,1@ECOLOR=225,225,223
com.apple.macbook-retina-gold
com.apple.device-model-code
MacBook8,1@ECOLOR=235,215,191
com.apple.macbook-retina-space-gray
com.apple.device-model-code
MacBook8,1@ECOLOR=155,158,159
MacBook8,1@ECOLOR=157,157,160
NSImage *image =[[NSWorkspace sharedWorkspace] iconForFileType:@"com.apple.macbook-retina-gold"];
如何获取型号/标识符(sysctl hw.model 被 system_profiler 替换)?
NSPipe *outputPipe = [NSPipe pipe];
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/sbin/system_profiler"];
[task setArguments:@[@"SPHardwareDataType"]];
[task setStandardOutput:outputPipe];
[task launch];
[task waitUntilExit];
NSData *outputData = [[outputPipe fileHandleForReading] readDataToEndOfFile];
NSString *hardware = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
并解析模型标识符或您的属性列表序列化