Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Restore iOS 4.3-5.0 compatibility

  • Loading branch information...
commit 427da1b690885ae71ec5c1fc9f0c6b5323ae7efc 1 parent 861b7e5
@x2on x2on authored
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:)]) {

might be worth adding a comment noting that this API is iOS6 only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ image = [UIImage imageWithData:imageData scale:scale];
+ }

convention is to put the else and brackets on the same line

} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ else {
+ UIImage *imageWithoutScale = [UIImage imageWithData:imageData];
+ image = [UIImage imageWithCGImage:imageWithoutScale.CGImage scale:scale orientation:UIImageOrientationUp];
+ }
+ return image;
+}
+
#pragma mark Public
- (CGSize)sizeForView:(UIView *)view {
@johnboiles

convention is to put the else and brackets on the same line

} else {
@johnboiles

might be worth adding a comment noting that this API is iOS6 only

Please sign in to comment.
Something went wrong with that request. Please try again.