Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if device is an iPad or iPhone not working

I am currently updating an app and I need to know whether the app is being used in an iPad or not.

I checked online and I found the code below. I used the iPad simulators in Xcode and ran both if statements. but whenever I run the code, nothing happens (the print message does not print) does this code work with simulators or am I doing something wrong?

When I check if it is UIUserInterfaceIdiom.phone the print statement executes, but I am using an iPad in the simulator.

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad){
        print("This is an iPad")
        redoButton.layer.position.y -= 500



    }

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

Thank You

like image 543
Alex Merlin Avatar asked Apr 09 '18 02:04

Alex Merlin


People also ask

How do I check the status of my Apple device?

Go to mysupport.apple.com. Sign in with your Apple ID. Choose your device. You can see details about the support that you're eligible for—including hardware repairs and technical support.

How do I make sure my iPad and iPhone are connected?

If want your iPhone and iPad to work smoothly together, you have to go through a couple of steps. Log in with the same Apple ID on both devices, connect the devices to the same WiFi network, turn on Bluetooth and Handoff. Handoff is easy to turn on. You go to 'Settings' and tap 'General' > 'Airplay and Handoff'.

Why are my iPad and iPhone not connected?

Make sure that iOS software is up to date. On your iOS device, go to Settings then Bluetooth and make sure that Bluetooth is on. If you can't turn on Bluetooth or you see a spinning gear, restart your iOS device. Unpair the Bluetooth accessory and put it back in discovery mode, then try to pair it again.


1 Answers

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

But you need to make your app a universal app.

like image 99
Wendra Avatar answered Oct 14 '22 09:10

Wendra