iOS app with preloaded images - ios

I'm creating an iOS app with some preloaded data which includes images, it will have between 150 and 200 images. This images are not downloaded from a server, since the app won't connect to the internet.
I'm wondering about if saving the images locally can cause any problem, what is the max size that I can use to store them? Can this affect the app's performance? Anything else that I should be aware of?
Thanks in advance!

Over the air cellular maximum download is now 100MB since the iOS 7 launch.
Your maximum app size is 2GB with a maximum binary size of 60MB. With 200 images I don't think you'll hit the 2GB mark, so long as you use the proper compression techniques.
The only thing that would affect your app's performance is the way the images are presented. If they're really large images, 10+ MB you'll most likely hit memory problems in older devices and if you go larger, memory problems in newer devices. There's plenty of techniques like tiling in a scroll view to get around these problems but it requires you splice up your images and create multiple resolution versions of the image.

If your app is greater than 50MB (at the time of writing) because of the images being included then users will need WiFi to install it.
Other than that, your performance concerns should be around how many of the images you will have loaded into memory at any one time and how you can reduce that number.

Related

iOS app crashes because images use too much ram

I know this is a stupid problem, but this is my first real app that I have to make, I have no one to ask and I looked up this problem and found no other similar problems.
My app crashes on real devices with no exception. I saw in the simulator that uses too much RAM and after a while I got to the conclusion that the pictures I am using are to blame.
The app is structured in this way: it has 8 viewControllers for different things: for example, it starts with one which lets the user select the avatar with which he/she will play and here I have two pictures, next is a viewController which shows the stats for that avatar and here it is another picture and so on. The problem is that each picture uses 40MB of RAM to be displayed and things add up so the app uses more than 300MB of RAM when the user gets to the gameviewCOntroller where the game is. Because of this, on devices like iPAD 2 or iphone 4 it crashes, but not on iphone 5.
I tried to set the images both from "images.xcassets" and from a ".atlas" folder, but the result is exactly the same. The pictures have a dimension of no more than 1500x1999px, they are in png format.
Also, I saw that if the app were to start directly into the gaveViewController it would use 180MB so the other viewController remain in memory or something like that. Should I "clear" them or something similar?
//-------update-------
This is what I got from Instruments:
Memory is a big deal on mobile devices, there is not a clear answer to you question, but I can give you some advices:
If your images are plain colors or have symmetric axes use resizable images. You can just use one line of pixel multiplied by with or height to cover the entire screen using a small amount of memory
Image compression doens't have effects when the image is decompressed. So if you have a png that is 600kb and you are thinking that converting in a 300kb will lower memory usage is only true for "disk space" when an image is decompressed in memory the size is widthXheightXNumber_of_channelXbit_for_channel
resize images: if are loading a 2000px square image into memory and you show it inside an image view of 800 px square, resize before adding it.You will have just a peak while resizing, but later it will use less memory
If you need to use big images, use tiling techniques such as CATiledLayer
If you don't need an image anymore get rid of it. It's ok to have an array of path to images, but not an array of full uncompressed images
Avoid -imageNamed it caches images and even if Apple says that this cache is released under memory pressure, you don't have a lot of control on it and it could be too late to avoid a crash
Those are general advices, it's up to you if they fit your requirements.
You should definitely follow Andrea's advices.
Additionally you should consider setting the image size to exactly what your need is. You're saying that you've tried to set them from xcassets so you have full control over the images you're loading, which is great (compared to downloading an image that you cannot modify).
I highly suggest you read some documentation on using Asset catalog files. This will allow you to have high-resolution image for bigger screens that also have more memory, and smaller ones for older devices, which is what you want here.
Also, note that 1500x1999px is still a very big size for most mobile devices.
More links about screen-size:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html
http://www.paintcodeapp.com/news/iphone-6-screens-demystified

on what factors does the size of IPA depends?

I am working on an App, that includes iphone(4,5 potarit only) and Ipad(Landscape as well Potarit). App includes 120 MB of IMAGES and the folder size of my project is 123 MB.
But I made its ipa, that goes to 185 MB . I am worried about the size of the build. How it happened to become 185 MB.
On what factors it is depending upon?
How Can I reduce the size of my build?
Will there be any problem uploading this app to the app store?
There are total of 15*3=45 NIB files in my project.
part (3) - "Will there be any problem uploading this app to the app store?" :
The maximum size of .ipa in AppStore depends on your internet connection.
For app to be downloaded over 3G, the maximum size should be 100MB. Over Wi-fi connection or iTunes the maximum size is 2GB.
part (2)
To reduce the iPA size you can reduce the size of the images. Generally in an application you do not require high resolution images (not more than what the device supports).
If there are images you can make the application download from some external server, that would be better. That way you can download the images the first time app is launched and save in the sandbox of the app and they can be used later in the app by fetching from the sandbox. This can reduce your iPA size considerably.
part(1)
Generally the binary size is less than the actual folder size. I could not see from where your iPA size is increasing.
As far as I know
1 . ipa file size mostly depends on the Images size.
2 . So try to ask your designers to reduce the image for saving the memory or try to use the .jpg files for images except for splash screens,icons. No need to worry about the xib files .
3 . There is no need to worry about the size while releasing the app . Only issue is takes some time to download from the iTunes.
The size of application mostly not depend on the code but on the resources you have added into your application like images, video and sound files.
Most time number of images to support the different display need to add more images cause large size of IPA but for that I think the best way is use stretchable images that decrease IPA size around upto 40 to 60 percent and very neat and clean. do not include over side video and mp3 just compress them at optimum level so user experience will be great. Size could be around 40 mb is best for general ios application
Another approach is to download necessary assets during the first launch.
Pro: user will only get images that compatible with his device
Con: there must be a stable internet connection to download the images. Wi-Fi is preferred, because 3G is not always free of charge for user.

Starling AS3: A lot of textures, memory warning iOS

I'm using the AssetManager class in Starling to load a lot of textures, around 600-700 png-files. All files are not loaded on start and I use multiple AssetManagers to hold the images. On start it loads around 70 images to 3 different managers and while it's loading I get some memory warnings on iOS.
iPhone appName[644] : Received memory warning.
iPhone appName[644] : Application received a memory warning from the system.
iPhone SpringBoard[74] : Received memory warning.
iPhone MobilePhone[199] : Received memory warning.
I've tried to load them at the same time and tried start each load when the other one is completed. I've also tried System.gc(); and System.pauseForGCIfCollectionImminent(0.1); between each load, this fixed the problem on iPhone 5 (7.0.4) but not on an iPhone 3gs (6.1.3).
Starling version: 1.4.1
Anyone got any tips on how to solve this?
Typically from a mobile development standpoint there is never a "one size fits all" solution. There are many different screen sizes and hardware configurations. In order to combat this many developers will generate -as mentioned previously, Sprite Sheets. Using this method the application only has to load one image vs -in your case hundreds. Image loaders take quite a while connecting to a memory address to initiate a texture upload to the GPU -I can't even image how slow it must be for that many assets.
This texture packer is phenomenal, and also aides with another feature many dev's incorporate. Asset Densities. Wherein the iPhone 3Gs a dev will load a set of sprite sheets developed for smaller screen sizes, a larger sprite sheet with twice the sized assets will load for a tablet or some of the higher end devices. This method will not only solve your memory issues but make your application look much better over a broader range of devices.
Here is a link to the Starling Wiki on multi-resolution development.
Of all the changes you can make to a project "for the better" the ones mentioned above are very high on the list.
You should NOT be loading 600-700 images. Even if they load successfully, you'll have a lot of problems with the performance. Instead, use atlas/sprite sheets.
http://wiki.starling-framework.org/manual/textures_and_images
And for even more optimized work, use ATF Textures instead png.
http://wiki.starling-framework.org/manual/atf_textures
If you run XCode Instruments against your app you'll see the total load of the device, which is the real metric that determines how often you receive memory warnings.
If your total load % is above 80%, expect a slew of constant memory warnings. The GC will try and run every time causing drastic clipping in framerate.
There's a bug about this and Adobe is working on it, but the main solution is to simply use less memory. Downscale textures for devices that have lower resolutions, etc...
https://bugbase.adobe.com/index.cfm?event=bug&id=3649713

Xcode instruments low memory warning app killed on 2 MB live bytes

My app crashes with low memory warning on device, even though the max live bytes in instruments is 3 MB tops. I do use a lot heavy PNG's in my app(in about 20 ViewControllers) , I believe ARC should've taken care of it.
Here is the screenshot.
Reduce size of heavy png files. Png file must be good in resolution but size must be less not more than 2 MB.I also had the same problem but used Three 20 Framework which solved my issue because it manages Images files allocation perfectly. Now a days it seem Three 20 is not getting updated but still you can try it in a sample app if you want . Here is the link :http://three20.info/
I figured it out myself. The problem was that I was doing animation using a bunch of PNG's.
So when using this
image.animationImages=imageFrames;
it was caching all the images in memory each time it was called, which led to dirty memory filling up and crashing the application. So, after using it each time to release the image cache we need to do this
image.animationImages=nil;

Do I really need lower-resolution images for older iOS devices?

I am developing an iphone application and i am using a background picture for my app. I know that before iphone 4 , the resolution of the screen was 480x320 and after 960x640. I read that i should use 2 images like : MyImage.png and MyImage#2x.png with the 2 different resolutions and the app will know which one to choose according to the phone. My question is very simple. If i just use the 960x480 , whats the difference? I am developing on an iphone 3gs and i am using this resolution and everything works perfect. So why have a small resolution for these phones?
The difference, in my opinion, is the following: the phone is going to resize the doubled-resolution to half the size, and this will lead to (1) the final image is not as smooth as if you would have exported it from a image application like Illustrator or Photoshop - at least from my own experience, when I export both resolutions, in non retina devices, the images don't look as good if I had exported the normal resolution. Also (2) the device will waste time/performance to make this conversion, although I don't know how much it is significant. And (3) finally, you may overload memory with no need, considering that the doubled sized images are bigger files, and you could use smaller files instead.
If you don't mind about this issues, you can go ahead. Try yourself.
If nothing else, the high-resolution images will tax the memory much more. One full-screen image at 320✕480 is around 600K in memory, whereas the 640✕960 is almost 2.5M, four times as much. On the older devices the memory is much more scarce than on the new ones and you might run into problems later in the development cycle, when there are more resources in play.
Even if you are able to test the app on all older supported devices and you can guarantee that there are no immediate performance problems or visual glitches, the app will take more memory, forcing the OS to kill other apps more frequently (= worse overall user experience).
if you use one version of image, (960x640) , there will be a memory overhead when the app run on non-retina. you dont need to display the high res in non-retina, only in retina display, making two versions of images .png and #2x.png will tell ios which image version it should load, depends on what device is currently in use.

Resources