IOS NSBundle usage

Source: Internet
Author: User

1. Obtain the info. plist details of the app.

Version: Bundle version

 NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

Application ID: Bundle identifier

NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];

Application name: Bundle display name

NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];

Bundle name

NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];

 

2. Application language Localization

App localization macro

#define XLocalizedString(key, comment)        [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]

Two key-value pairs in the Localizable. strings file, for example

"None" = "OK ";
"none" = "none";

Macro usage: (return NSString *)

LocalizedString ("none", "This is a comment ")

 

3. Get the file path and file in the package

Get app package path

NSString *path = [[NSBundle mainBundle] bundlePath];

App resource directory path

NSString *resPath = [[NSBundle mainBundle] resourcePath];
 

Obtain a. bundle under the Resource Directory

NSString* path = [resPath stringByAppendingPathComponent:@"a.bundle"];NSBundle *bundle = [NSBundle bundleWithPath:path];
 

Path of the readme.txt file of the received apppackage

NSString *path = [[NSBundle mainBundle] pathForResource:@"readme" ofType:@"txt"];

 

Article content from: http://www.cnblogs.com/xiaodao/archive/2012/07/03/2574703.html
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.