Detecting if iPhone or iPad without opting for Universal App

602 views Asked by At

I really want this to work:

if UIDevice.current.userInterfaceIdiom == .pad {
    print("iPad")
} else {
    print("not iPad")
}

However, my app only prints "not iPad" even though I am using an iPad. I have Devices (under Deployment Info) set to iPhone. If I change this to Universal it works, but I don't want a universal app, I just want to be able to detect if an iPhone or iPad is being used (even though the app is for iPhones, due to compatibility mode it still can be run on iPads).

So how can I detect if the device is an iPad or iPhone without changing my app to Universal? Thanks

4

There are 4 answers

0
Dogan Altinbas On BEST ANSWER

You can check the model:

if UIDevice.current.model.hasPrefix("iPad") {
     print("it is an iPad")
} else {
     print("it is not an iPad")
}
1
Kevin Lewis On

One thing you can do is get the inner-screen width of the page. Phones are generally below 786 px and you can call everything else an iPad. Use can do something like this

    var width = window.innerWidth;
    If (width > 786px) {
        print(‘ipad’);
    } else {
        print(‘not ipad’)
    }
0
Lal Krishna On

iPhone Only app can be downloaded to iPad. But in current scenario, we doesn't have device that's much smaller resolution(deployment target: 9).

OBJ-C

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && [[[UIDevice currentDevice] model] hasPrefix:@"iPad"]) {
        // This app is an iPhone app running on an iPad
        NSLog(@"This app is an iPhone app running on an iPad");
    }

Swift

if UIDevice.current.userInterfaceIdiom == .phone, UIDevice.current.model.hasPrefix("iPad") {
    print("iPad")
}
0
Krunal On

Try this,

print("Model - \(UIDevice.current.model)")

enter image description here