Resolved Storing image locally

Discussion in 'iOS Programming' started by DennisBlah, Jul 12, 2014.

  1. DennisBlah, Jul 12, 2014
    Last edited: Jul 12, 2014

    DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    Hey all, I'm trying to store images locally for offline use.
    The code below works fine, in simulator, but on a actual device (iPhone 5S on iOS7.1.2) it doesn't store the image to the documents folder
    Code:
                    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                    
                    NSData *imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: [NSString stringWithFormat: @"%@images/%@/%@", theHost, theSub, theImageName]]];
                    UIImage *image = [[UIImage alloc] initWithData: imageData];
                    NSString *jpegFilePath = [NSString stringWithFormat:@"%@/%@/%@", [paths objectAtIndex:0], theSub, theImageName];
                    
                    NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 6.0f)];
                    [data2 writeToFile:jpegFilePath atomically:YES];
    
    However I'm doing the same thing with a html page, in same sub, and that works fine
    Code:
    NSString *filePath = [NSString stringWithFormat:@"%@/%@/%@/index.html", [paths objectAtIndex:0], theSub, pageName];
        
        // Download and write to file
        NSURL *downloadURL = [NSURL URLWithString: url];
        NSData *urlData = [NSData dataWithContentsOfURL:downloadURL];
    
        [urlData writeToFile:filePath atomically:YES];
    
    p.s. before starting I am checking if the sub exists, also at the image, if not, then creating it.

    Hopefully someone can help me out because I really don't understand this thing... In simulator it works fine :-(

    ---------
    Sorry it was a stupid fault. At the image check it never met the if statement :eek:

    Cheers!:cool:
     
  2. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2

Share This Page