Tuesday, July 16, 2013

Programmatically detecting isDevice iPhone 5 ?


Define global  condition as below in your global classes:

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

Used C functions:
DBL_EPSILON = will give the smallest value that will make a difference when adding with one.  Smallest number such that 1.0 + DBL_EPSILON  != 1.0.
fabs = gives absolute value of x (a negative value becomes positive, positive value is unchanged).

Now simply you can detect iPhone 5 as :
if(IS_IPHONE_5){
            NSLog(@"I am iPhone 5");
}
else {
              NSLog(@"I am not iPhone 5");

}

No comments:

Post a Comment