1

I'm using dataWithContentsOfFile on a PNG image and the iOS Simulator returns a value that differs from an iOS Device. My device is a 64-bit iPad Air (iOS 8.3) and my simulator is set to iPad Retina iOS 8.3. Here's the code that I'm using:

    NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
    NSData *data = [NSData dataWithContentsOfFile:sourcePath];
    NSString *hash = [self md5Hash:data]

    // Results on device: 2D25F346396FB00BEB27754ED1B56310
    // Results on simulator: 55016FD1AB3DA0F882FEA85D5ABCA2ED

I tested my hash function with a string, and it works fine regardless of device. I'm not going to display the results of the dataWithContentsOfFile method, but I can assure you that they're different.

Update: Testing dataWithContentsOfURL works fine, example:

    NSURL *fileURL = [NSURL URLWithString:@"https://www.google.com/images/srpr/logo11w.png"];
    NSData *data = [NSData dataWithContentsOfURL:fileURL];
    NSString *hash = [self md5Hash:data]

    // Results on device: 57E396BAEDFE1A034590339082B9ABCE
    // Results on simulator: 57E396BAEDFE1A034590339082B9ABCE
Leo
  • 24,596
  • 11
  • 71
  • 92
Ngoan Nguyen
  • 747
  • 2
  • 9
  • 19
  • 1
    I'd say the difference of the MD5 is because of the different architectures using different number formats. Could it be that the resizable iPad runs in 32-bit? Possibly related: http://stackoverflow.com/questions/697361/md5-hash-calculates-differently-on-server – Gyfis Jun 10 '15 at 23:48
  • I'm sorry, I made a mistake. I'm using the Retina iPad, which is 64-bit. I've tested the hash code against text strings and they give the same results on simulator vs device in my case. – Ngoan Nguyen Jun 10 '15 at 23:54
  • I would guess that the file is different. – Hot Licks Jun 11 '15 at 01:25
  • (Consider that when you ask for an image file, the file system will select one of several synonyms based on the display resolution.) – Hot Licks Jun 11 '15 at 02:07

1 Answers1

1

I'm going to guess that it's Xcode applying PNGCrush to your image... so it is actually not the same file.

cbiggin
  • 1,942
  • 1
  • 17
  • 18
  • This is it, on device builds pngcrush manipulates the image. I had to set the pngcrush directive to NO for it to work correctly. The interesting thing is that for simulator builds, pngcrush is not applied to the images. – Ngoan Nguyen Jun 11 '15 at 18:56