nsbundle

Using NSBundle to load my resources

笑着哭i 提交于 2019-12-21 16:55:39
问题 I wanted to separate my resources, nib files and localization files into a common reusable bundle. And so I created a bundle for my ios application and specified resources to be included inside the bundle using build phases, copy bundle resources. But, now if I try to load the bundle, I am not able to load the bundle. I try using [NSBundle allBundles] and the array shows only the main apps bundle. I also tried to enumerate the directory for NSApplicationPath but again the only bundle

How do NSBundle pathForResource:ofType: and UIImage imageWithContentsOfFile: handle scale and device modifiers?

折月煮酒 提交于 2019-12-21 03:28:22
问题 In my iOS resource folder, I have the images: foo~iphone.png foo@2x~iphone.png foo~ipad.png foo@2x~ipad.png I load them with: NSString *fileName = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"png"]; UIImage *image = [UIImage imageWithContentsOfFile:fileName]; Experimentally: On the iPhone, filename is /path/to/bundle/foo~iphone.png , and on the retina iPhone, it loads the @2x version. On the iPad, filename is /path/to/bundle/foo~ipad.png , and on the retina iPad, it loads the @2x

How to check if a Storyboard exists in a specific NSBundle

江枫思渺然 提交于 2019-12-20 20:20:09
问题 I'm making an app that makes use of a framework that I'm creating. The framework contains storyboards but in some cases the project making use of the framework will need to override the storyboard by providing a new one. So my goal is to check if a storyboard with a given name exists in [NSBundle mainBundle] , if not then I will get the base version from my framework. I have tried getting the storyboard from the main bundle and checking for the result being nil but it throws an exception if

iPhone/iPad: Unable to copy folder from NSBundle to NSDocumentDirectory

孤者浪人 提交于 2019-12-20 15:27:23
问题 I am trying to copy a folder in my NSBundle which contains quite a number of images. I tried doing it with these codes. NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:@"Images"]; NSString *resourceDBFolderPath = [[[NSBundle

Why “loadNibNamed” methods return array?

半城伤御伤魂 提交于 2019-12-20 03:12:31
问题 When we use the loadNibNamed method to get nib file, why will return a array, is not a nib file name corresponds to a nib file? I try to print this array's count, I found it always return 1. I hope you can help me to explain, thank you every much! Here is the snippet of code : NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TestView" owner:self options:nil]; NSLog(@"array's count is %ld",array.count); 回答1: This is because NIB/xib files can also contain more than one view representation

Replacing images in the bundle at run time

ぃ、小莉子 提交于 2019-12-19 10:25:18
问题 Can I replace images in bundle at run time? Basically, I have some images part of my bundle and also I will have them from the server if there is any change in the image. Can I place them in the bundle at run time so that I need not to change my code to pick the image? 回答1: You cannot change the contents of an Application bundle. It is however possible to store the images in the Application's documents folder. Then you'll be able to overwrite those images in case they need to be changed.

Checking the presence of a file in the bundle

我们两清 提交于 2019-12-19 10:18:04
问题 How can we check if a file is present in the external bundle loaded in the app or not before fetching it? 回答1: If you only want to know if it's there so you can decide whether to load it or not, I'd just attempt to load it and check if the object returned is nil. If it is, you know it doesnt exist in the bundle. 回答2: To check if a file exists in the bundle, use the NSBundle class. NSString *path = [[NSBundle mainBundle] pathForResource:@"somefileinbundle" ofType:@"png"]; if (!path) NSLog(@

Count of images in my [[NSBundle mainBundle] bundlePath]

懵懂的女人 提交于 2019-12-18 16:55:25
问题 How can you find count of images in [[NSBundle mainBundle] bundlePath] at particular my folder.... Eg: /Users/Nag/Library/Application Support/iPhone Simulator/4.2/Applications/4409487C-1035-4329-B38A-B6F21E00FC63/MakeUp_IPhone.app/" MyFolder " 回答1: http://www.ericd.net/2009/06/iphone-getting-images-from-your-bundle.html http://www.cocoabuilder.com/archive/cocoa/239638-number-of-images-in-main-bundle-folder-iphone.html Check the above links. They may provide a solution to your problem. Here is

Get fileSize of info.plist to prevent piracy

浪尽此生 提交于 2019-12-18 10:17:25
问题 I'm trying to put anti-piracy code in my app. The previous answer to this (which I can't link to because of my member status - sucks) can be easily countered, since the "SignerIdentity" string can be looked for and replaced in the binary using a hex editor. Instead, checking the fileSize of the info.plist file and comparing it to a reference value sounds more solid (since the info.plist is getting modified here and there when cracking the app). How would I do that? I tried the following but

Multiple Localized .strings Files in iOS App Bundle

放肆的年华 提交于 2019-12-17 18:42:13
问题 I have a fairly complicated project, consisting of several large localized sub-projects. Most of my sub-projects are localized through a single Localizable.strings file. This file is copied into a SubProjectName.bundle target, which is used in conjunction with a SubProjectName.a static library in the main project. This works fine. However, one of my sub-projects contains many localized .strings files. This project fails to read strings in any language other than English , regardless of how