Read info.plist in custom framework

2019-07-11 02:48发布

问题:

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

回答1:

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



回答2:

Thank you for your answers.

Solution are as shown below:

[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"ASD"]