how to get version of default browser on my mac os x

≯℡__Kan透↙ 提交于 2019-12-08 09:06:19

问题


I want to get system information in mac using objective C. I am searching a lot but did not got single line of code for my use.They provided solutions via javascript but i want them in objective C. Provide me some help to go ahead.


回答1:


You can use launch services to get the path to the default browser as below

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

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

Now read the CFBundleShortVersionString from the info.plist.




回答2:


Here you go :

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

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

Updating my answer




回答3:


This is tested and works well

        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"]);

Dont forget to add AppKit framework



来源:https://stackoverflow.com/questions/15404723/how-to-get-version-of-default-browser-on-my-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!