Home News Forum Social Networking Support Us Advertise

Spanish Lesson 1 ($1.99)

aWake!Gently ($1.99)

The Bird & The Snail - Knock Knock - Deluxe ($4.99)

Match-It Trains ($0.99)

Tangled ($0.99)

iFlatter ($0.99)

The 15 puzzle ($0.99)

Tap Forms Database ($8.99)

Higher or Lower Card Game (Hi Lo) ($0.99)

Red Pixel ($0.99)

Time-Shift Radio ($0.99)

Want your application advertised here? Only $10/week!

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)
Junior Member
 
Join Date: Aug 2008
Posts: 2
Rep Power: 0
fatter is on a distinguished road
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)
Senior Member
 
Jume's Avatar
 
Join Date: Jul 2008
Location: Slovenia, EU
Posts: 246
Rep Power: 1
Jume is on a distinguished road
Send a message via Skype™ to Jume
Default

check following:

NSData
+ (id)dataWithContentsOfURLNSURL *)aURL

and

UIImage
+ (UIImage *)imageWithDataNSData *)data
Jume is offline   Reply With Quote
Old 02-08-2009, 10:29 AM   #3 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 15
Rep Power: 0
teras is on a distinguished road
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)
Senior Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 575
Rep Power: 0
tkilmer is an unknown quantity at this point
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)
Junior Member
 
Join Date: Aug 2008
Posts: 15
Rep Power: 0
teras is on a distinguished road
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)
Member
 
Join Date: Jan 2009
Location: Madrid (Spain)
Posts: 52
Rep Power: 1
estupefactika is on a distinguished road
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


» Advertisements


» Stats
Members: 8,231
Threads: 20,200
Posts: 90,217
Top Poster: RickMaddy (2,121)
Welcome to our newest member, OneGlobe
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:45 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0