Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-01-2008, 06:32 AM   #1 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 2
Default Save image into cache ?

Hi,

I have been talking about how to save text into cache in this topice :
Apple - Support - Discussions - How to save data in order to reuse on ...

Now I would like to know how should I proceed to save an PNG or JPG that is online into the iPhone.

This is the wished process

My App launches, retrieves an XML file from a web server.
In the XML file there is string that is the image URL, (example : http://www.google.es/images/nav_logo4.png)

The image is stored into the iPhone's cache.
Then I use this image as an UIImageView in my View.

This my question

1. Once I have the URL, how do I download and save into cache. What should I use ?

2. How to access to that cached data then ?
fatter is offline   Reply With Quote
Old 12-01-2008, 09:52 AM   #2 (permalink)
Registered Member
 
Jume's Avatar
 
Join Date: Jul 2008
Location: Slovenia, EU
Posts: 253
Send a message via Skype™ to Jume
Default

check following:

NSData
+ (id)dataWithContentsOfURLNSURL *)aURL

and

UIImage
+ (UIImage *)imageWithDataNSData *)data
Jume is online now   Reply With Quote
Old 02-08-2009, 10:29 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 17
Default

I have some problems with memory management.

I thought to use the init- messages instead, like this:
Code:
	NSData * data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myURL]];
	UIImage *img = [[UIImage alloc] initWithData:data];
	[myImageView setImage:img];
	[img dealloc];
	[data dealloc];
If I use it like this, when code reaches [data dealloc] it segfaults.

Why is this happening?
teras is offline   Reply With Quote
Old 02-08-2009, 10:30 AM   #4 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

You do not ever call dealloc on an object. You should use release instead.
tkilmer is offline   Reply With Quote
Old 02-08-2009, 10:42 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 17
Default

Quote:
Originally Posted by tkilmer View Post
You do not ever call dealloc on an object. You should use release instead.
Thank you!
I'm still a newbie in memory management in Obj-c
teras is offline   Reply With Quote
Old 02-24-2009, 05:03 AM   #6 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Madrid (Spain)
Posts: 55
Default

One question, is the cache persistent? or empty when app terminates?

What happen when you open your app again? Are still images in cache?
estupefactika is offline   Reply With Quote
Reply

Bookmarks

Tags
cache, image

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,921
Threads: 38,707
Posts: 169,890
Top Poster: smasher (2,554)
Welcome to our newest member, noisyblue
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:42 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0