Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7575467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:41:50+00:00 2026-05-30T16:41:50+00:00

I have code that will check to see if an image is on the

  • 0

I have code that will check to see if an image is on the phone or not (the name being retrieved from the db), and if not, it runs this code:

NSString *urlString = [NSString stringWithFormat: @"http://www.vegashipster.com/%@",image_path];                        
NSData *imageData = [[NSData alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]];

NSLog(@"saving jpg");
UIImage *image = [[UIImage alloc] initWithData:imageData];//1.0f = 100% quality

[UIImageJPEGRepresentation(image, 1.0f) writeToFile:myFilePath atomically:YES];
NSLog(@"saving image done");
NSLog(@"URL String: %@",urlString);
NSLog(@"http://www.vegashipster.com/%@",image_path);

rest_image = [UIImage imageNamed:image_path];

[image release];
[imageData release];

This code works just fine on the simulator, but on the iPhone, the screen freezes for a few seconds (downloading the image, I think), then loads the page, but with no image visible. The next time you hit that page, there is no freeze. So I believe the file is being created, but it’s a messed up image file, and therefore not displayed.

I’ve already broken this code up so that it runs in it’s own thread, and again, it works in the simulator. I had thought that if it ran behind the scenes, there would be less of a chance that the image data would get messed up, but the exact same thing happens (minus the freezing). Does anyone know what I am doing wrong with this code? Thanks for any and all help/comments.

Edit

And yes, the images being downloaded are strictly .jpg

Edit 2

I seen:

Make sure you are writing to your DOCUMENTS directory, which you have read+write access to. Otherwise you won’t get any files.

at http://www.iphonedevsdk.com/forum/iphone-sdk-development/15628-file-weirdness-files-written-disk-do-not-appear-nsfilemanager-defaultmanager.html . Could this be my issue?

NSString *image_path = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 5)] stringByReplacingOccurrencesOfString:@"../"
NSString *myFilePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:image_path];

Last Edit

Well, I found what I believe to be my answer at How can I get a writable path on the iPhone? . It pretty much states I cannot save image files where my own image files are located inside the build. If this is incorrect, please let me know and I will try your way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:41:51+00:00Added an answer on May 30, 2026 at 4:41 pm

    Sorry, forgot about this thread completely. I did end up fixing this issue. Here is what I did:

    NSFileManager* fileManager = [NSFileManager defaultManager];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *libraryDirectory = [paths objectAtIndex:0];
    
    NSString *myFilePath = [libraryDirectory stringByAppendingPathComponent:image_path];
    
    BOOL fileExists = [fileManager fileExistsAtPath:myFilePath];
    
    if (fileExists){
        hotel_image = [UIImage imageWithContentsOfFile:myFilePath];
    }else{
        [NSThread detachNewThreadSelector:@selector(downloadImage:) toTarget:[HotelsDetailsViewController class] withObject:image_path];
    
        fileExists = [fileManager fileExistsAtPath:myFilePath];
    
        if (fileExists){
            hotel_image = [UIImage imageWithContentsOfFile:myFilePath];
        }else{
            hotel_image = [UIImage imageNamed:@"hdrHotels.jpg"];
        }
    }
    

    In short, I found my app’s library directory and saved there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that compiles and runs on MSVC++ but will not compile
I have the following code that will check to see if the div text
I have some code that will be accessed from two threads: class Timer{ public:
Does anyone have some code that will take a TimeZoneInfo field from .NET and
I have the this code that will create excel file and work sheet then
I am trying to add a magic fields plugin image code that will check
I have the following code which will check to see if the following fields
Javascript I have code that will hide various sections in a MS CRM form
I currently have some code that will produce a crash dump when my application
I have some Javascript code that will programmatically register an COM interop assembly by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.