Images disappear after app released to appstore - iphone

There is something very weird in my app after it has been released to the appstore.
Some of the UIImages i used are just missing and seen black from some reasons.
I have checked many times before in device and simulator and it appeared just fine.
Some notes:
I did drag the files and check COPY - the images are in the library for sure
Images DO appears in Copy Bundle Resources under Build Phases
I used these 2 lines in order to get the image:
[UIImage imageNamed:#"email_icon.png"] and [UIImage
imageNamed:#"facebook_icon"]
And i have just noticed that the extensions of the images are PNG not png - maybe is that the reason?
Appreciate your assistance!

Can you replicate this issue on your device? If not I'd recommend deleting the current version from your device and redeploying. You may have cached images on your device which are not allowing you from seeing the issue.
Secondly, yes, filenames on the device are case sensitive. Also make sure that you are properly naming the files and it is not simply a spelling mistake or change from an image name.
Per your line of code you are missing the file extension on the second image
[UIImage imageNamed:#"email_icon.png"] and [UIImage imageNamed:#"facebook_icon"] <-- what type of file is facebook_icon?

Related

Can't load a new image from .xcassets file

I'm unable to load an image that I added to a .xcassets file today.
let image = UIImage(named: "slider_star")
print(image) // nil
Other older images from the exact same assets file load just fine (in the exact same spot in code). I can see the image just fine in .xib files, and if I put it in a UIImage in a .xib file it appears just fine in the simulator, too.
I've tried cleaning my build folder, restarting Xcode, using different simulators, and loading it as an Image Literal (can select it from the image list, but simulator crashes when it tries to render the image). I also made sure the target membership is correct, and that the assets file is in copy bundle resources, and that the image files are indeed inside the assets file in Finder. Also all settings for the image set are the same as other working image sets.
Any idea why this is happening?
edit: More things I've tried from suggestions in the comments:
change name from "star" -> "slider_star"
check that the color space of all images are the same as working ones
check that there is no extra white space at the end of slider_star.
also tried making another new image set, and re-using some of the confirmed working images in it, but this also comes back nil. I think this probably rules out any issue with the image files themselves, at least. It's almost like xcode isn't seeing the updates to the .xcassets file, but that's strange because the updates are showing up and working fine in .xib files.
Finally figured this out. This is a fairly large project with multiple targets, and it seems that the code in the target I'm working in is for some reason looking at the .xcassets file from another target (I checked the other xcasset file's target membership, and it's not included in the target I'm working in, so I don't understand why this is happening).
I can work around this by putting my images in the other xcasset file (don't really like this), or specifying the bundle with UIImage(named:in:with:).
If anyone knows why this is happening, I'd love to fix the root issue (maybe it's not an issue, and I'm just not understanding how it's supposed to work). I'll let this sit for 24 hours before accepting this as an answer.

UIImageViews don't load in UIScrollView using imageNamed method

Can someone tell me the difference between these two means of loading an UIImageView?
iconView.image = [UIImage imageNamed:anIconFileName];
and
iconView.image = [UIImage imageWithContentsOfFile:anIconFileName];
I ran into a situation where when using the imageNamed method I had non-deterministic behavior loading the UIImageViews as subviews on a UIScrollView. The UIImages would load in the simulator, but not on a device using may iMac. But when I moved to my Mac Air everything worked as expected in both the simulator and the device? With further investigation, I found that it was nondeterministic when it worked. I was trying to load 5 UIImageViews and sometimes I would get 1 or maybe two. Getting any to load at all seemed to depend on the size of the *.png files I was trying to load.
When I changed with the imageWithContentsOfFile method everything worked as expected... reliably.
The UIImages didn't seem to be to large - about 100K each. Any thoughts would be helpful.
First thing - have you checked the name of image, because simulator load case insensitive image as well, while device will not load that.
imageNamed - this method takes file name.
imageWithContentsOfFile - this method take complete file path of that file name.
So above code which you have mentioned is dummy code or actual code, and if that is actual code then you need to be sure that with imageNamed you have to pass file name and with imageWithContentsOfFile you have to pass file path.
Check out this article for difference between these two method -
http://www.jorambarrez.be/blog/2012/04/19/ios-imagenamed-vs-imagewithcontentsoffile/
It's nothing to do with the UIScrollView just check the way you imported the images to Xcode. You should add files selecting the option:
Create groups for any added folders.
That way the folder will show in yellow (instead of blue) and imageNamed will work fine.

App failing to see #2x images

This is driving me nuts. Been searching for 2 days, and I can't find any real solution or explanation for why this is happening. I know there are threads here on SO, as well as some other places, but they have been no help. I have read the Apple documentation on the matter.
I have normal and #2x images in my app. They are named correctly (edit_image.png, and edit_image#2x.png). They are sized correctly (normal is 60x60, #2x is 120x120). They are both being copied into the app bundle, and when I examine the contents, I can see them both in the root.
I am grabbing the image by calling [UIImage imageNamed:#"edit_image"]. It never grabs the 2x image. It only sees the 1x image. However, if I check the scale first, and use this code:
if ([[UIScreen mainScreen] scale] == 1) {
NSLog(#"test");
editImage = [UIImage imageNamed:#"edit_image"];
} else {
editImage = [UIImage imageNamed:#"edit_image#2x"];
}
Then it does grab the correct image. I have tried everything. I deleted the high res from the project, cleaned, re-added the high res, cleaned and then built, no dice. I deleted all the images, and re-added them, no dice. I have done everything I can think of. What the hell is going on here?
Are you creating universal application for both iPhone & iPad. If universal app is there then you need to create 3 set of images:
1) edit_image~iPad.png
2) edit_image~iphone.png
3) edit_image#2x~iphone.png
each with the same resolution of 72 pixels/inch. While you need to provide double size for that #2x image which I think you've already done this.
Now, try the below code
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"edit_image" ofType:#"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath];
Important: When creating
high-resolution versions of your
images, place the new versions in the
same location in your application
bundle as the original.
Source: http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/SupportingResolutionIndependence/SupportingResolutionIndependence.html
Two silly mistakes that I've made that can cause this problem:
Accidentally naming the small
versions #2x instead of the large
ones
Having the large versions be
slightly missized (by one pixel)
You don't need to add the "#2x" bit, or have the if-else logic at all. Just use [UIImage imageNamed:#"edit_image"].
I was suffering from the exact same problem, and finally found a solution (after 2 days of searching).
In my case the name of the #2x image didn't exactly match the normal sized image: tileSet.png and tileset#2x.png.
What made this so difficult to discover is that the #2x file did have the correct name in Finder and in XCode. I was only able to discover the problem by opening the image in Preview and looking at the Inspector. I don't know enough about the Mac file system to explain how this happens, but once I renamed the file to gibberish, then renamed it back to tileSet#2x.png everything started working as expected.

Hi-Res #2x image not being picked up for tab bar item

I have a TabBarController that sets the image for the tab like so, in the -init method:
self.tabBarItem.image = [UIImage imageNamed:#"tabImage.png"];
I have a tabImage#2x.png file in the resource. In the iPhone 4 simulator or the phone, the hi-res image isn't being picked up - the low res version is simply being scaled up.
Any ideas why this might be?
EDIT: Some more info:
If I try and explicitly use tabImage#2x.png (or just tabImage#2x) then the tab image I see is extremely large and blown up beyond the bounds of the tab, as if it's being scaled from 60px to 120px. So it looks like whatever name is supply is being treated as a scale=1.0 image.
Note that the simulator is not case-sensitive, but the device is. Make sure case matches EXACTLY. If you've changed the case of the filename at some point, you'll need to clean and rebuild. Sometimes, for the simulator, I've had to actually blow away the folder in Library/Application Support/iPhone Simulator/4.3/Applications/ to get the rebuild to pick up the renamed image.
Always use
[UIImage imageNamed:#"foo.png"]
This will work on 3.x and 4.x devices, and on the 4.x Simulator. Devices with Retina Displays (and the 4.x simulator) will magically pick up the #2x versions of your images; iOS has been modified to be smart about this function and #2x.png files.
Make sure you have both the #2x.png and the normal.png added to the project file, and do a full clean & build. As others have mentioned, verify the size of the images, too; apparently if they're not exactly 2x the dimensions it won't work (I haven't verified this myself).
If you leave the .png off, it will only work on iOS 4.0. So if you're building a 4.0+ only app, you can ask for:
[UIImage imageNamed:#"foo"]
If you have only one hi-res image and want to use it on both Retina and non-Retina devices, then you'll have to change view.contentMode to scale to fit.
I had the same problem. It turned out that my png was not square. Solution: make it square and it will work.
Are you sure the file has been added to the XCode project and is visible in the project explorer?
I had this problem as well.
Make 2 images:
30x30 pixels
60x60 pixels
Suffix the 60x60pixel image with #2x. For example, tabBarImage#2x.png. Then, in your storyboard or code, you can specify the regular one, tabBarImage.png, and iOS will choose the #2x version at its discretion.
You can leave the .png off now. I believe it will still work, but you may try that.
I just went through a few hours of redoing art in The Gimp and trying to get it recognized and loaded by my app on an iPhone 4.
I ran into the problem described with certain images with a #2x extension not being recognized and loaded.
I was not able to discern any pattern. My images are all loaded using [UIImage imageNamed:#"<name>.png"] into a singleton. I inspected the image scale settings post-startup and some were 1.0 (the old art) and some were 2.0 (the new art).
The only way I was able to resolve this problem was to delete and re-add the high resolution images that were not being recognized.
Two silly mistakes (both of which I've made before) that can cause this problem:
Accidentally naming the small
versions #2x instead of the large
ones
Having the large versions be
slightly missized (by one pixel)
you need 2 versions of your images and both ned to be at the same location in the project folder and added to the project
image.png 60x60
image#2.png 120x120
then simply use [UIImage imageNamed:#"image.png"]
did it this way with selfmade buttons and it worked for me (iOS 4.1)
Another thing to look out for is having two images with the same name.
I had the same issue. The #2x image had the wrong build target checked (ServiceTests instead of MyProject).
I had exactly the same problem.
Make two images: im1.png and im1#2x.png
Call imageNamed: with the first one.
Note, imageNamed: doesn't initialize UIImage, hence use it as transient [[UIImageView new] initWithImage:[UIImage imageNamed: #"im1.png"]] or initialize UIImage yourself.

iphone - not loading ~ipad image

I have 3 images on the same place on my app's bundle: "image~iphone.png", "image#2x~iphone.png" and "image~ipad.png".
when I do
UIImage *imageU = [UIImage imageNamed:[[NSBundle mainBundle] pathForResource:#"image"
ofType:#"png"]];
BOth, the iPhone and iPhone 4 hires versions load fine, but not the ipad image. When I run on iPad, I get nil on imageU.
Yes, the image is there, the name is correct (iphone~ipad.png).
Why is that? any clues?
thanks.
I discovered that the solution for that is: do not use any extension on the iPad images. This tilde trick is not working for iPad. One more buggy stuff that makes us waste time.
Possible daft attempt, but is the ipad image copied into the correct target when you add it as a resource? By that, I mean - of you right click the image and get info, does it have the iPad ticked as it's target?
I ran into the same problem with launch images. Despite what the docs say, naming a file with a ~ipad suffix doesn't do anything. You need to set the UILaunchImageFile~ipad key and use a separate name for your launch images on iPad, e.g., DefaultiPad.png and DefaultiPad-Landscape.png, then make sure to just set UILaunchImageFile~ipad to DefaultiPad (no .png suffix) and it will pick up the variants correctly.
image "image~ipad.png" will show HD quality on iPad because in ios 5.1 "~ipad.png" is used to show HD quality image of resolution 2048*2048.Test this naming conservation on iPad,it will work.