Search code examples
imagefilesystemsappcelerator

Appcelerator images not being saved


TiSDK 1.7.1
iOS 5.0

I'm attempting to take the URL of an image that is passed to the app and store it in applicationDataDirectory.

I've written a function that takes the url, creates an ImageView, passes it to .toImage() and then writes it to a file.

http://pastie.org/3064770

When I run it in the simulator and go to the applicationDataDirectory in finder to view the image it's the generic placeholder image that is stored, not the image that is being passed.

Thoughts?


Solution

  • I think the problem is you are saving the image when the image has not downloaded from the web yet - it has no data. The image is not available as soon as you get the image property - you have to wait for the 'load' event. Dawson Toth has a great example on how to create a caching image view which saves the file when the image has loaded. iOS only as the 'load' event doesn't fire in Android in 1.7.X.

    Also, Titanium will only load the image when it is displayed on the screen. So if you want to download it in the background, use a HttpClient.