priore

Detect the type of iPhone Device independent from iOS vers

Oct 18th, 2014
708
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Detect the type of iPhone Device independent from iOS version (updated)
  2. typedef NS_ENUM(NSInteger, DeviceTypes)
  3. {
  4.     DeviceTypeUnknown,
  5.     DeviceTypeiPad,
  6.     DeviceTypeiPhone3,
  7.     DeviceTypeiPhone4,
  8.     DeviceTypeiPhone5_6,
  9.     DeviceTypeiPhone6p
  10. };
  11.  
  12. static inline DeviceTypes DeviceType()
  13. {
  14.     CGFloat scale = [UIScreen mainScreen].scale;
  15.     CGSize size = [UIScreen mainScreen].bounds.size;
  16.     CGFloat r = MAX(size.width, size.height) / MIN(size.width, size.height);
  17.     if (r < 1.5) {
  18.         return DeviceTypeiPad;
  19.     } else if (r == 1.5 && scale == 1.0) {
  20.         return DeviceTypeiPhone3;
  21.     } else if (r == 1.5 && scale == 2.0) {
  22.         return DeviceTypeiPhone4;
  23.     } else if (r > 1.5 && scale == 2.0) {
  24.         return DeviceTypeiPhone5_6;
  25.     } else if (r > 1.5 && scale == 3.0) {
  26.         return DeviceTypeiPhone6p;
  27.     }
  28.  
  29.     return DeviceTypeUnknown;
  30. }
  31.  
  32. static inline BOOL orientableDashboard()
  33. {
  34.     return (DeviceType() == DeviceTypeiPad || DeviceType() == DeviceTypeiPhone6p);
  35. }
RAW Paste Data