得到mac电脑的生产日期(通过一个私有库))
作者:
皮蛋豆腐酱油 | 来源:发表于
2019-10-21 19:35 被阅读0次- (NSString *)getProduceDate {
NSString *modelIdentifier = @"";
NSString *cmd1 = @"system_profiler SPHardwareDataType | grep 'Model Identifier'";
modelIdentifier = [self executeCommand:cmd1];
modelIdentifier = [modelIdentifier substringFromIndex:24];
modelIdentifier = [modelIdentifier stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSString *date = @"";
NSString *path = @"/System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/English.lproj/SIMachineAttributes.plist";
NSDictionary *SIMachineAttributesDic = [[NSDictionary alloc] initWithContentsOfFile:path];
for (NSString *s in SIMachineAttributesDic.allKeys) {
if ([s isEqualToString:modelIdentifier]) {
NSDictionary *infoDic = [[SIMachineAttributesDic objectForKey:s] objectForKey:@"_LOCALIZABLE_"];
date = [infoDic objectForKey:@"marketingModel"];
break;
}
}
return date;
}
- (NSString *)executeCommand:(NSString *)cmd
{
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/bash"];
NSArray *arguments = [NSArray arrayWithObjects: @"-c", cmd, nil];
[task setArguments: arguments];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file = [pipe fileHandleForReading];
[task launch];
NSData *data = [file readDataToEndOfFile];
NSString *retStr = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
[file closeFile];
return retStr;
}
本文标题:得到mac电脑的生产日期(通过一个私有库))
本文链接:https://www.haomeiwen.com/subject/vkrxvctx.html
网友评论