Last active
August 29, 2015 14:05
-
-
Save izackp/2ee0ca4b6c731b254e55 to your computer and use it in GitHub Desktop.
A more accurate check for retina in iOS. (Assumes all future devices are retina)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSString (Formatting) | |
- (NSString*)stringWithOnlyLetters; | |
- (NSString*)stringWithOnlyNumbers; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSString+Formatting.h" | |
@implementation NSString (Formatting) | |
- (NSString*)stringWithOnlyLetters { | |
NSCharacterSet *numSet = [[NSCharacterSet letterCharacterSet] invertedSet]; | |
return [[self componentsSeparatedByCharactersInSet:numSet] componentsJoinedByString:@""]; | |
} | |
- (NSString*)stringWithOnlyNumbers { | |
NSCharacterSet* letters = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet]; | |
return [[self componentsSeparatedByCharactersInSet:letters] componentsJoinedByString:@""]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @attention Not accurate on the simulator, and will not be accurate on future devices that use retina resources but actually have a non retina display*/ | |
extern bool hasRetinaDisplay(void); | |
extern bool usesRetinaResources(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "RetinaDisplayMethods.h" | |
#import <NSString+Formatting.h> | |
#import <sys/utsname.h> | |
bool hasRetinaDisplay() { | |
struct utsname systemInfo; | |
uname(&systemInfo); | |
NSString* code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; | |
NSString* deviceType = [code stringWithOnlyLetters]; | |
NSString* deviceVersion = [code stringWithOnlyNumbers]; | |
int version = [deviceVersion intValue]; | |
if ([deviceType isEqualToString:@"iPad"]) | |
{ | |
if (version < 30) | |
return false; | |
} | |
if ([deviceType isEqualToString:@"iPod"]) | |
{ | |
if (version < 50) | |
return false; | |
} | |
if ([deviceType isEqualToString:@"iPhone"]) | |
{ | |
if (version < 40) | |
return false; | |
} | |
return usesRetinaResources(); | |
} | |
bool usesRetinaResources() { | |
return ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && | |
([UIScreen mainScreen].scale == 2.0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment