0

我想使用目标 C 在 mac 中获取系统信息。我搜索了很多,但没有得到单行代码供我使用。他们通过 javascript 提供了解决方案,但我希望它们在目标 C 中。为我提供一些帮助以继续。

4

3 回答 3

2

您可以使用启动服务获取默认浏览器的路径,如下所示

LSGetApplicationForURL((CFURLRef)[NSURL URLWithString: @"http:"],
                                kLSRolesAll, NULL, (CFURLRef *)&appURL);

NSString *infoPlistPath = [[appURL path] stringByAppendingPathComponent:@"Contents/info.plist"];

现在从 info.plist 中读取 CFBundleShortVersionString。

于 2013-03-14T10:17:58.453 回答
0

干得好 :

NSString *userName=NSUserName();
NSLog(@"UserName: %@",userName);

NSArray *ipAddress=[[NSHost currentHost] addresses];
NSLog(@"IP Address=%@",ipAddress[0]);

更新我的答案

于 2013-03-14T10:47:42.627 回答
0

这是经过测试并且运行良好

        NSWorkspace *nsSharedWorkspace = [NSWorkspace sharedWorkspace];
         NSString *nsAppPath = [nsSharedWorkspace fullPathForApplication:appName];
         NSBundle *nsAppBundle = [NSBundle bundleWithPath: nsAppPath];
         NSDictionary *nsAppInfo = [nsAppBundle infoDictionary];

//Now you can print all dictionary to view all its contents and pick which you want
         NSLog(@"%@",nsAppInfo);

//or you can get directly using following methods
         NSLog(@"%@",[nsAppInfo objectForKey:@"CFBundleShortVersionString"]);
         NSLog(@"%@",[nsAppInfo objectForKey:@"CFBundleVersion"]);

不要忘记添加 AppKit 框架

于 2013-03-15T12:56:25.263 回答