iPhone / iPad IOS How To Get Framework Bundle Version - ios

Trying to get a .framework 's bundle version. Tried to find the file using path for resource and then use NSBundle something like...
NSString *path = [[NSBundle mainBundle] pathForResource:#"SomeFramework" ofType:#"framework"];
NSBundle *bundle = [[NSBundle alloc] initWithPath:path];
_version = [bundle objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
But path keeps coming back nil......
Better way?

NSArray *ar = [NSBundle allFrameworks];
for (NSBundle *b in ar) {
NSLog(#"%#",[b objectForInfoDictionaryKey:#"CFBundleName"]);
NSLog(#"%#",[b objectForInfoDictionaryKey:#"CFBundleShortVersionString"]);
}

Related

Objective - C Getting blank value for CFBundleShortVersionString - App Version

I am programmatically getting the App Version and getting the blank value for the app version. I am also getting 0 for build number - kCFBundleVersionKey.
Below is the code for the same.
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey: #"CFBundleShortVersionString"];
NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
I have already added both the values in info.plist file and General tab for the Target.
I think it's helpful for you
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];
NSLog(#"Version %#",version);
OR
NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];
NSString *version = infoDictionary[#"CFBundleShortVersionString"];
NSString *build = infoDictionary[(NSString*)kCFBundleVersionKey];
NSString *bundleName = infoDictionary[(NSString *)kCFBundleNameKey];
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleShortVersionString"];
Try this:
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey: #"CFBundleShortVersionString"];
this code is working in my project for getting Version

Read info.plist in custom framework

I want to read the files contained within the framework info.plist my own creation. When I try to read, the rferans it've read his file info.plist framework applications.
I need to read both. How can I do it? Could you help?
NSLog(#"*** %#", [[[NSBundle mainBundle] localizedInfoDictionary] valueForKey:#"ASD"]);
NSLog(#"*** %#", [[[NSBundle mainBundle] infoDictionary] valueForKey:#"ASD"]);
NSLog(#"*** %#", [[[[NSBundle allFrameworks] objectAtIndex:0] infoDictionary] valueForKey:#"ASD"]);
First create bundle by using your framework path:
NSString* mainBundlePath = [[NSBundle mainBundle] resourcePath];
NSString* frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:#"YourFrameworkBundle.bundle"];
frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
Then access Info Dictionary or what you want
Thank you for your answers.
Solution are as shown below:
[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:#"ASD"]

iOS 9 localization broken (returning english when My phone is in french)

A issue appears on my app when installing it on a iOS9 device.
All strings are now translate in english instead of french on a french device.
NSString * temp = NSLocalizedString(key, #""); //<-- incorrect English translation
NSString * temp2 = [[NSBundle mainBundle] localizedStringForKey:key value:#"" table:nil]; //<-- incorrect English translation
NSString * frenchBundlePath = [[NSBundle mainBundle] pathForResource:#"fr" ofType:#"lproj"];
NSString * temp3 = [[NSBundle bundleWithPath:frenchBundlePath] localizedStringForKey:key value:#"" table:nil]; //<-- CORRECT
so my french localized string exist and is correct, but the [NSBundle mainBundle] seams to be the english one...
EDIT:
on iOS7 and iOS8
[[NSBundle mainBundle] preferredLocalizations] returns fr
on iOS9
[[NSBundle mainBundle] preferredLocalizations] returns base
so What should I do ?
EDIT 2 :
I found a work around, but not really happy with it
NSString * preferedLanguage = [[[[NSLocale preferredLanguages] objectAtIndex:0] componentsSeparatedByString:#"-"] objectAtIndex:0];
NSString *preferedBundlePath = [[NSBundle mainBundle] pathForResource:preferedLanguage ofType:#"lproj"];
NSBundle *preferedBundle = [NSBundle bundleWithPath:preferedBundlePath];
NSString *preferedString = [preferedBundle localizedStringForKey:key value:fallbackString table:nil];

What is interpretation for bundleForClass returns nil and how that can be corrected?

I am preparing an XCTest and to perform the test I need to load a resource from test bundle. Therefore I use:
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:#"item" ofType:#"plist"];
The problem is that bundleForClass returns nil. How can that be happening, as every class is tied to a bundle which was loaded from? Is there any setting to be corrected to make it working?
You can do like,
NSString *path = [[NSBundle mainBundle] pathForResource:#"item" ofType:#"plist"];

Not able to retrieve info.plist data by -pathForResource method?

In my application I am not able to get the plist using the below code. I am using Xcode 4.5
and here is my code for retrieving plist,
NSBundle *thisBundle = [NSBundle mainBundle];
NSDictionary *theDictionary;
NSString *commonDictionaryPath;
if (commonDictionaryPath = [thisBundle pathForResource:#"newfonts-Info" ofType:#"plist"])
{
theDictionary = [[NSDictionary alloc] initWithContentsOfFile:commonDictionaryPath];
}
Note:- If I try to retrieve a text or xml file then the above code works fine.
To get the Info plist as a dictionary, you can just do:
NSDictionary *theDictionary = [[NSBundle mainBundle] infoDictionary];
Use
[[NSBundle mainBundle] infoDictionary];
Calling infoDictionary on any bundle instance will return something (thought it may only contain private keys).
Try this code
SArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString* fooPath = [[NSBundle mainBundle] pathForResource:#"newfonts-Info" ofType:#"plist"];
NSLog(fooPath);
contentArray = [NSArray arrayWithContentsOfFile:fooPath];
NSLog(#"%#",contentArray);
or this can also works with NSDictionary
NSString* plistPath = [[NSBundle mainBundle] pathForResource:#"newfonts-Info" ofType:#"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
NSLog(#"%#",dict);
i hope it helps you.
Finally I find the answer by self
I just open the documents directory and open the application.app file and got to see that the plist file which is shown as application-Info.plist in the bundle is seen just as Info.plist
so I changed the above code and and retrieve the dictionary
NSString *commonDictionaryPath;
commonDictionaryPath=[[NSBundle mainBundle]pathForResource:#"Info" ofType:#"plist"];
NSDictionary *info=[NSDictionary dictionaryWithContentsOfFile:commonDictionaryPath];
NSLog(#"path %#",commonDictionaryPath);

Resources