[英]how to get version of default browser on my mac os x
我希望使用目标C在mac中获取系统信息。我正在搜索很多但没有单行代码供我使用。他们通过javascript提供了解决方案,但我希望它们在目标C中。给我一些帮助继续。
您可以使用启动服务获取默认浏览器的路径,如下所示
LSGetApplicationForURL((CFURLRef)[NSURL URLWithString: @"http:"],
kLSRolesAll, NULL, (CFURLRef *)&appURL);
NSString *infoPlistPath = [[appURL path] stringByAppendingPathComponent:@"Contents/info.plist"];
现在从info.plist中读取CFBundleShortVersionString。
干得好 :
NSString *userName=NSUserName();
NSLog(@"UserName: %@",userName);
NSArray *ipAddress=[[NSHost currentHost] addresses];
NSLog(@"IP Address=%@",ipAddress[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框架
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.