So here's the deal:
I have an image in the Resources folder of custom framework that I use as a default for classes in the framework. However, when I create these classes in projects that link against my framework they fail saying they can't find the image. I'm guessing the NSBundle's +mainBundle does not search the correct paths for my classes to find this image when linked in a different project. Is this correct? If so, where should I be looking for my image? I hope this makes sense (it's awfully late) and thanks for the help!
For an application, the +mainBundle will be the application bundle (e.g., Foo.app). Frameworks are their own bundle, which you can find using +bundleForClass: or +bundleWithIdentifier:.
It's likely your image isn't getting put in the main bundle. You may have to use NSBundle directly to construct the path to your image. What does the built .app file hierarchy look like in terms of the image?
Related
Can we overlay the file to our custom path or we have to overlay the file to exact folder structure location as in libs?
For example, I want to overlay the constants.js (/libs/cq/ui/widgets/source/constants.js) file, in this adobe recommended Copy this file to /apps/cq/ui/widgets/source/constants.js for overlaying, but in my project that folder structure is not there, so I have copied to the custom path in apps folder and tested the changes and overlaying is working fine.
The file needs to have the same path as the one in libs except for replacing 'libs' with 'apps'. It does not work with custom paths*. If the project does not already have the structure, you can always create it. Don't forget to update the META-INF/Vault/filter.xml file to register the new path with projects package definition.
*Technically you can change the configs to add new searchpaths. But do remember that you might have to share the AEM instance with different tenants and sticking to the usual conventions goes a long way in having a predictable setup. I honestly don't see a reason to do this, it is already an acceptable practice to overlay under '/apps'. The filters on package provide enough flexibility to get along with other tenants while modifying similar areas.
I think you want to create the overlay in your custom project under /apps. If my assumption is correct, then you can certainly do it.
Taking your example in consideration, /libs/cq/ui/widgets/source/constants.js can be overlayed to /apps/<your-project>/cq/ui/widgets/source/constants.js by adding an entry in the Apache Sling Resource Resolver Factory configuration.
See this answer for the detailed steps. I hope this helps.
I'm kind of new to ios developing and was wondering could I navigate through my own application with NSFileManager.
I have a folder inside my application and would like to see what files are in it and don't want to use hardcoded file names.
Sounds like you need to get to know NSFileManager's contentsOfDirectoryAtPath: error: method (documentation linked for you).
To look within your own application bundle, pass a path of "[[NSBundle mainBundle] resourcePath]". This would give you a path to the "Resources" folder within your application bundle. If you look at the linked documentation, you'll see NSBundle provides a few other potential ways to get paths to interesting locations within your application package.
How can I add third party images to be be used in the Phonegap Framework in Xcode?
I have a few images to include.
The linking to the various websites work but the images are not showing, it is just a question mark.
<li>Google<img src="googlelogo.png"/>
Please help. Thank you :)
I'm assuming that you want to refer to an image that you include with your PhoneGap project. Just make sure any images you want to reference are included inside the www folder of your project.
Think of the www folder like you would a directory on a server somewhere. Your index.html page sits on the root, and you can create any number of sub-directories you'd like... just as you would on a regular server.
<li>Google<img src="googlelogo.png"/>
The above code suggests you have a file at: www/googlelogo.png
<li>Google<img src="myImages/googlelogo.png"/>
The above code suggests you have a file at: www/myImages/googlelogo.png
There are lots of the frameworks available for different purposes, but I want to create framework library for my some of my classes -- in that all the .m files are loaded in single .a file and it's used with the list of header files.
Can any one tell me how to create a framework?
This webpage should give you the necessary information when creating your own framework.
http://accu.org/index.php/journals/1594
Hope this helps!
You can create a "Cocoa Touch Static Library" project in Xcode.
The iPhone application I'm working on comes bundled with 20MB of images in the application directory and I need to write new images to the documents directory over time.
Ideally I'd like to move the initial folder to the documents directory, copying the folder would mean wasting 20mb of the users disk space.
Failing that I'll create the required structure in the documents directory and leave the initial images in place, but that would mean checking in two places every time I want to display an image.
Is there a way of automagically searching the application bundle and documents directory when building an image path?
To answer your first concern: you can’t move anything out of the application bundle. Any modification of said bundle invalidates the signature and will render your app non-functional on all but jailbroken iOS devices.
Now, onto the challenge of copying images out: To find something in the main bundle, you’d do this:
NSString *imagePath = [[NSBundle mainBundle] pathForResource:#"myImage"
ofType:#"png"];
For an image, though, you’re better off doing this:
UIImage *imageFromBundle = [UIImage imageNamed:#"MyImage.png"];
That will do caching for you in a way that loading the image directly won’t.
I don’t know why you’d want to copy the image out, but it seems that maybe you have an initial set of images that may or may not be replaced. I’d recommend, then, instead of copying out of the bundle, look for the image first in the Documents folder, and if it isn’t there, copy it out of the bundle. That allows you to replace the images without copying from the bundle or modifying the bundle.
AFAIK the bundle is read only. So while your "move" idea is a good one, I am fairly certain Apple does not allow for it currently.
Is there a way of automagically
searching the application bundle and
documents directory when building an
image path?
I can say that I have done this for images but you have to create the magic yourself. I wrote a class that I would call with the name of the image as a parameter. That class would first look in the documents directory, then look in the bundle and finally look to a website for the image. When it found the image it returned the UIImage. A bit of a pain to initially setup, but once in place it is quite useful and I am glad I did it.