Common methods for NSBundle in iOS

Source: Internet
Author: User

1. Get info.plist details for your app

Version number: 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 macros

#define Xlocalizedstring (key, comment)        [[NSBundle Mainbundle] Localizedstringforkey: (key) value:@ "" Table:nil]

Key-value pairs in two localizable.strings files in English, such as

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

Macro usage: (Return to NSString *)

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

3. Get the file path and file in the package

Get the App package path

NSString *path = [[NSBundle mainbundle] bundlepath];

App Resource Directory path

NSString *respath = [[NSBundle mainbundle] resourcepath];

Get the Resource directory under A.bundle

nsstring* path = [Respath stringbyappendingpathcomponent:@ "A.bundle"]; NSBundle *bundle = [NSBundle Bundlewithpath:path];

Get the Readme.txt file path for the app package

 nsstring *path = [[NSBundle mainbundle] pathforresource:@ "readme" oftype:@ "TXT"]; 

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.