Read info.plist in custom framework - ios

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

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

How can I get my own bundle's infomation?

I want to get some information of "myBundle.bundle" such as version,create time whitch identify the bundle. Thest information may wirite by myself localed in myBundle.bundle.
Are there any recommend method for doing this ?
I try like this, but not success:
I put a plist named Info.plist into the root of myBundle.bundle.
read the info like below,but the info is nil:
self.bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:#"myBundle" ofType:#"bundle"]];
NSDictionary * info = [self.bundle infoDictionary];
You can Use the following line of code to get Bundle Version
NSString * bundleVersionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleVersion"];
NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];
NSString build = infoDictionary[(NSString)kCFBundleVersionKey];
This will give all the info. that is stored in plist like version,bundle version, display name, etc.

NSBundle pathForResource: returns nil

I am attempting to access a .txt file from my supporting files folder in Xcode on iOS using the following piece of code:
NSString* filePath = #"filename.txt";
NSLog(#"File path: %#", filePath);
NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:#"txt"];
NSLog(#"File root: %#", fileRoot);
The first NSLog prints just what I expect it to print, but the last NSLog always simply prints
File root: (null)
Accessing text from the file after (attempting to) reading it into memory also simply gives me a (null) printout.
The solution for this problem is probably right under my nose, I just can't seem to find it. Any help is very appreciated! Thanks in advance.
filePath already contains the suffix ".txt", therefore you must not specify it
again when locating the resource. Either
NSString* filePath = #"filename.txt";
NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:nil];
or
NSString* filePath = #"filename";
NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:#"txt"];

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

iPhone / iPad IOS How To Get Framework Bundle Version

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

Resources