如何在我的mac os x上获取默认浏览器的版本

时间:2013-03-14 08:50:41

标签: objective-c c macos browser system-information

我想使用目标C在mac中获取系统信息。 我正在搜索很多,但没有得到单行代码 我的用途。他们通过javascript提供解决方案,但我想要他们 客观C. 为我提供一些帮助。

3 个答案:

答案 0 :(得分:2)

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

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

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

现在从info.plist中读取CFBundleShortVersionString。

答案 1 :(得分:0)

你走了:

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

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

更新我的回答

答案 2 :(得分: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框架