Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check iphone model using swift

Tags:

ios

swift

How we can check model of iPhone (e.g iPhone 4/ iPhone5) in Swift. Using following code I can check whether it is iPhone of iPod.

let iphoneModel = UIDevice.currentDevice().model
if (iphoneModel == "iPhone"){
        println("Iphone 4")
    }

I need to know specifically which iPhone model it is.

like image 570
Saqib Omer Avatar asked Sep 30 '14 09:09

Saqib Omer


People also ask

How do I find my iPhone model name Swift?

Basic Swift Code for iOS AppsOpen Xcode → New Project and add the below code in ViewController's viewDidLoad method. UIDevice. current. model, gives you a model whether you have an iPhone, iPad, UIDevice.current.name gives you a name identifying the device.

How do I find my iOS device model?

Go to Settings > General > About. To the right of Model, you'll see the part number. To see the model number, tap the part number.

How do I find my iPhone and iPad in Swift?

To detect current device with iOS/Swift we can use UserInterfaceIdiom. It is an enum in swift, which tells which device is being used. The interface idiom provides multiple values in it's enum which are.

What is device model?

A device model is the analytical expression developed based on theoretical and experimental study. Variables and constants that make up this Analytical Expression are model parameters. In other words, device parameters are used to reproduce the actual element characteristics on a simulator.


1 Answers

Swift 4 + iPhone Xr, Xs, Xs Max support

import UIKit

enum UIUserInterfaceIdiom : Int {
    case Unspecified
    case phone
    case pad
}

struct ScreenSize {
    static let screenWidth = UIScreen.main.bounds.size.width
    static let screenHeight = UIScreen.main.bounds.size.height
    static let screenMaxLength = max(ScreenSize.screenWidth, ScreenSize.screenHeight)
    static let screenMinLength = min(ScreenSize.screenWidth, ScreenSize.screenHeight)
}

struct DeviceType {
    static let iPhone4OrLess  = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.screenMaxLength < 568.0
    static let iPhoneSE = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.screenMaxLength == 568.0
    static let iPhone8 = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.screenMaxLength == 667.0
    static let iPhone8Plus = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.screenMaxLength == 736.0
    static let iPhoneXr = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.screenMaxLength == 896.0
    static let iPhoneXs = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.screenMaxLength == 812.0
    static let iPhoneXsMax = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.screenMaxLength == 896.0
    static let iPad = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.screenMaxLength == 1024.0
}

And use :

 if DeviceType.iPhoneXsMax {
      print("is Max here")
 }
like image 183
Nicolas.B Avatar answered Oct 15 '22 14:10

Nicolas.B