1
votes

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
For testing purpose, iPhone apps runs on iPad but once Your app becomes live users can't be able to download it on iPad.Kuldeep
This is not true. iPhone apps can be downloaded onto an iPad; they run in iPhone 3.5" resolution.Paulw11
Check this question It seams you have the same problem, your application is not Universal.m1sh0
Why are you trying to check if it is an iPad? There may be another/a better way of dealing with your concern such as device capabilities.Paulw11
I’m trying to see if it’s an iPad because then I’ll load up a different storyboard and change so UI stuffJ.Treutlein

4 Answers

2
votes

You can check the model:

if UIDevice.current.model.hasPrefix("iPad") {
     print("it is an iPad")
} else {
     print("it is not an iPad")
}
0
votes

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
votes

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
votes

Try this,

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

enter image description here