Objective-C Tips & Trick - Prioregroup.com
[Objective-C] Detect the type of iPhone Device independent from iOS vers
       
back

// Detect the type of iPhone Device independent from iOS version (updated)
typedef NS_ENUM(NSInteger, DeviceTypes)
{
    DeviceTypeUnknown,
    DeviceTypeiPad,
    DeviceTypeiPhone3,
    DeviceTypeiPhone4,
    DeviceTypeiPhone5_6,
    DeviceTypeiPhone6p
};

static inline DeviceTypes DeviceType()
{
    CGFloat scale = [UIScreen mainScreen].scale;
    CGSize size = [UIScreen mainScreen].bounds.size;
    CGFloat r = MAX(size.width, size.height) / MIN(size.width, size.height);
    if (r < 1.5) {
        return DeviceTypeiPad;
    } else if (r == 1.5 && scale == 1.0) {
        return DeviceTypeiPhone3;
    } else if (r == 1.5 && scale == 2.0) {
        return DeviceTypeiPhone4;
    } else if (r > 1.5 && scale == 2.0) {
        return DeviceTypeiPhone5_6;
    } else if (r > 1.5 && scale == 3.0) {
        return DeviceTypeiPhone6p;
    }

    return DeviceTypeUnknown;
}

static inline BOOL orientableDashboard()
{
    return (DeviceType() == DeviceTypeiPad || DeviceType() == DeviceTypeiPhone6p);
}






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com