Permalink
Browse files

Restore iOS 4.3-5.0 compatibility

  • Loading branch information...
1 parent 861b7e5 commit 427da1b690885ae71ec5c1fc9f0c6b5323ae7efc @x2on x2on committed Oct 25, 2012
Showing with 18 additions and 4 deletions.
  1. +18 −4 Classes/GHViewTestCase.m
View
22 Classes/GHViewTestCase.m
@@ -85,14 +85,13 @@ + (UIImage *)readSavedTestImageWithFilename:(NSString *)filename {
NSString *filePath = [self approvedTestImagePathForFilename:filename];
GHUDebug(@"Trying to load image at path %@", filePath);
// First look in the documents directory for the image
- UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfFile:filePath] scale:[UIScreen mainScreen].scale];
+ UIImage *image = [GHViewTestCase _imageFromFilePath:filePath];
// Otherwise look in the app bundle
if (image) GHUDebug(@"Found image in documents directory");
if (!image) {
- NSString* fileName = [[filename lastPathComponent] stringByDeletingPathExtension];
NSString* extension = [filename pathExtension];
- filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
- image = [UIImage imageWithData:[NSData dataWithContentsOfFile:filePath] scale:[UIScreen mainScreen].scale];
+ filePath = [[NSBundle mainBundle] pathForResource:[filename stringByDeletingPathExtension] ofType:extension];
+ image = [GHViewTestCase _imageFromFilePath:filePath];
if (image) GHUDebug(@"Found image in app bundle");
}
return image;
@@ -226,6 +225,21 @@ - (void)_setUp {
imageVerifyCount_ = 0;
}
++ (UIImage *)_imageFromFilePath:(NSString *)filePath {
+ UIImage *image;
+
+ NSData *imageData = [NSData dataWithContentsOfFile:filePath];
+ CGFloat scale = [UIScreen mainScreen].scale;
+ if ([UIImage respondsToSelector:@selector(imageWithData:scale:)]) {
+ image = [UIImage imageWithData:imageData scale:scale];
+ }
+ else {
+ UIImage *imageWithoutScale = [UIImage imageWithData:imageData];
+ image = [UIImage imageWithCGImage:imageWithoutScale.CGImage scale:scale orientation:UIImageOrientationUp];
+ }
+ return image;
+}
+
#pragma mark Public
- (CGSize)sizeForView:(UIView *)view {

0 comments on commit 427da1b

Please sign in to comment.