App crashing on ipad when downloading images - objective-c

im using the sdwebImage library to download images in tableview cell and display them.
the images are high resolution images. when the app launches, and starts loading, it suddenly crashes, without giving any errors, except sometime giving "received memory warning", and then the app crashes, its running on the simulator normally, but on an ipad, it is crashing,
the code where im putting the image in the cell:
- (void)setCellWithImage:(NSString *)imageURL
{
if (imageURL && [imageURL length]) {
[self.testingImageView sd_setImageWithURL:[NSURL URLWithString:imageURL]
placeholderImage:[UIImage imageNamed:#"ic_launcher"]];
}
}
any idea how to solve this issue?

I will suggest you to show in tableview use low quality image.
Get two image paths one for low quality image and another for high quality image. Show low quality image in Tableview and on click of particular image show high quality image.
There is only difference between simulator and phone is, Simulator doesnt have memory so on simulator this issue will not replicate.

Related

My app getting Crash

I am creating app like , which will take photos and shows the taken photos in thumbnail as scrolling part below the camera view .it is taking photos.but if i take more than 30 pictures my app is getting crash .So i connect my iPod with Xcode and i run , .I don't why it happens .I think may be memory issue .because i am taking more pictures.If it is memory issue please tell me what i should do for that .please help me.
Try this code to Reduce the size of image
- (UIImage )imageWithImage:(UIImage )image convertToSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return destImage;
}
Classic memory issue; you are using memory quickly enough that your app and, likely, the debugging conduit are being killed by the system.
To fix? Use less memory. Or, 'ore specifically, release the full sized images as soon as you have thumbnails generated.

iOS Universal Image Assets

For a new project my client wants to cover all iPhone and iPad sizes. For icons and sprites I'm not really gonna change the shapes of the images, but I'm in a bind with assets for my background images.
Looking at http://iosres.com I was wondering if there is some logic to cover both Landscape and Portrait 3:4 and 9:16 in one asset or should I simply make a set of iPhone and iPad and use UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad to figure out what to show before loading my views?
Also I'm wondering what's most effective for all the different device sizes. I know from experience that an iPad 3 wouldn't like to have a background image loaded on 4k resolution and that you want to avoid pixel differences so it won't trigger scaling in UIImageViews. Will iOS automatically figure out that the iPad 3 will use like the #1x variations, whereas the iPad Pro will load the #3x versions?
Yes iOS will automatically figure out which image to load at runtime and load #1x #2x or #3x depending upon the type of device. You don't need to do anything like UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad for each image.
Edit:
You can also add ~ipad suffix in image names so iOS will pick the appropriate background image for iPhones and iPads. i.e. image_name#2x~ipad.png and image_name#2x.png.

UIWebView crashing

I have a problem with using UIWebViews in an objective-C app we're developing. It crashes any Retina iPad. Both iPad 1 and 2 behave fine.
The web view is loaded from local HTML/CSS/JS and is dynamic content that contains pricing information so needs to be essentially a mirror of a website which is pre-downloaded to the device.
The page contains lots of images so I think this is memory related. I've tried reducing the payload on the page which stops the crashes. Obviously the stupidity of Apple to choose to quadruple resolution whilst only doubling memory is a root cause of why it works fine on non-retina devices, but how can I manage memory within the page to prevent iOS from destroying the entire app?
Does iOS automatically store imagery as 2048x1536x32bpp as a bitmap (theoretically 12MB per image?) irrespective of the file format? I've tried converting to JPG / PNG but with no effect on the crashes. Only reducing the volume of images present on the page stops the crashes. It's my first foray into iOS development, so please be gentle!
iOS won't change the resolution of the original images that the page loads, but of course it will de-serialize them from .png/.jpg to a bitmap in memory for display, so you should start by trying to reduce the resolution of the .png/.jpg images that the page loads.

UIWebView zoom with iPad Mini

My application developed for iPad contains two UiWebView's, and executes this code to make sure the content fits nicely on the screen:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[ipadWebMonth1 stringByEvaluatingJavaScriptFromString:#"document.body.style.zoom = 1.7;"];
[ipadWebMonth2 stringByEvaluatingJavaScriptFromString:#"document.body.style.zoom = 1.7;"];
}
Theres no way of me testing as I don't own one but as the screen size of the iPad mini is smaller, (I understand the amount of pixels are the same).
But surely this code would zoom the content in too much making some of in unable to be seen as I have user interaction disabled.
What options do I have here? Is there some sort of simulator I can download? Or is there a way of detecting the iPad mini and making a new function with different code?
Thanks,
Jack.
Try calling this in your viewDidLoad method (also make sure to remove your JavaScript code):
[_webView setScalesPageToFit:YES]
It makes the webpage scaled to fit exactly the webview's bounds.

How to save UIWebView content into photo library

How to save UIWebView Content into photo Library
-(IBAction)save:(id)sender{
UIImage* image = nil;
UIGraphicsBeginImageContext(webView.frame.size);
{
image = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
if (image != nil) {
UIImageWriteToSavedPhotosAlbum(image,self, nil, nil);
}
}
This code is saving empty page.
I've released an app (Web2Pic) doing that, and please trust me that UIGraphicsBeginImageContext(webView.frame.size);
can do nothing except getting a small image from the visible area in our UIWebView ;-(
The right way is a bit complex but it just works:
1.Use JavaScript in our UIWebView to get these float values:
//Whole page size in HTML coordinate
document.body.scrollWidth
document.body.scrollHeight
//UIWebView visible size in HTML coordinate
window.innerWidth
window.innerHeight
2.Now we can 'cut' the whole page into dozens of UIWebView-sized small pieces. Then we can capture every small pieces individually and save them into our Cache. I implemented this by calculating page-offsets and use UIGraphicsBeginImageContext(webView.frame.size); to get a array of images. In addition, you should cache the image array into the file system, or the app will eventually crash!
3.When we finally got all the small pieces, we can start a full-resolution context: UIGraphicsBeginImageContext(CGSizeMake(document.body.scrollWidth,document.body.scrollHeight));
4.Render every small images into the big context based on the coordinates. And be careful to the corners, the last image in every line/row may not be a full image.
5.There is still one step left: saving the big image. Do not save it into the PhotoAlbum, because iOS will automatically cut down the resolution of images in the album. Instead, we can save it into the file system and enable the app's iTunes File Share support, or even write a simple in-app photo manager.
Hope these can help ;-)
Yichao Peak Ji