1

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

J.Treutlein
  • 963
  • 8
  • 23
  • 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 Sep 05 '18 at 12:24
  • This is not true. iPhone apps can be downloaded onto an iPad; they run in iPhone 3.5" resolution. – Paulw11 Sep 05 '18 at 12:25
  • Check this [question](https://stackoverflow.com/questions/26414349/cannot-detect-device-as-ipad) It seams you have the same problem, your application is not Universal. – m1sh0 Sep 05 '18 at 12:27
  • 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 Sep 05 '18 at 12:31
  • I’m trying to see if it’s an iPad because then I’ll load up a different storyboard and change so UI stuff – J.Treutlein Sep 05 '18 at 21:11

4 Answers4

2

You can check the model:

if UIDevice.current.model.hasPrefix("iPad") {
     print("it is an iPad")
} else {
     print("it is not an iPad")
}
Dogan Altinbas
  • 268
  • 2
  • 11
0

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’)
    }
Kevin Lewis
  • 231
  • 1
  • 8
  • This won't work because an iPhone app runs at iPhone 4 resolution on an iPad, so the width that will be reported is an iPhone 4 screen width – Paulw11 Sep 05 '18 at 12:27
0

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")
}
Lal Krishna
  • 15,485
  • 6
  • 64
  • 84
0

Try this,

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

enter image description here

Krunal
  • 77,632
  • 48
  • 245
  • 261