투케이2K

36. (ios/swift) 모바일 디바이스 기기 해상도 확인 실시 - UIScreen main bounds size width height 본문

IOS

36. (ios/swift) 모바일 디바이스 기기 해상도 확인 실시 - UIScreen main bounds size width height

투케이2K 2021. 10. 30. 16:56
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT


[소스 코드]

    // MARK: [디바이스 해상도 확인 및 기기 종류 확인 실시]
    func checkDisplay() {
        // [뷰 전체 논리적 폭 길이 : css 측정 값]
        let _screenLogicalWidth = UIScreen.main.bounds.size.width
        
        // [뷰 전체 논리적 높이 길이 : css 측정 값]
        let _screenLogicalHeight = UIScreen.main.bounds.size.height
        
        // [뷰 스케일 값]
        let _screenScale = UIScreen.main.scale
        
        // [뷰 전체 물리적 폭 길이 : 실제 디바이스 표현 화소]
        let _screenPhysicalWidth = (_screenLogicalWidth * (_screenScale * _screenScale)) / 2
        
        // [뷰 전체 물리적 높이 길이 : 실제 디바이스 표현 화소]
        let _screenPhysicalHeight = (_screenLogicalHeight * (_screenScale * _screenScale)) / 2
        
        // [디바이스 기기 모델 확인 실시]
        let _deviceModel = UIDevice.current.model
        
        // [디바이스 기기 버전 확인 실시]
        let _deviceVersion = UIDevice.current.systemVersion
        
        // [디바이스 기기 이름 확인 실시]
        let _deviceName = UIDevice.current.name
        
        // [디바이스 OS 확인 실시]
        let _deviceOs = UIDevice.current.systemName
        
        print("")
        print("===============================")
        print("[ViewController >> checkDisplay() :: 디스플레이 화면 크기 확인]")
        print("[_deviceModel :: \(_deviceModel)]")
        print("[_deviceVersion :: \(_deviceVersion)]")
        print("[_deviceName :: \(_deviceName)]")
        print("[_deviceOs :: \(_deviceOs)]")
        print("[_screenLogicalWidth :: \(_screenLogicalWidth)]")
        print("[_screenLogicalHeight :: \(_screenLogicalHeight)]")
        print("[_screenScale :: \(_screenScale)]")
        print("[_screenPhysicalWidth :: \(_screenPhysicalWidth)]")
        print("[_screenPhysicalHeight :: \(_screenPhysicalHeight)]")
        print("===============================")
        print("")
        
        if _screenLogicalWidth == 390 && _screenLogicalHeight == 844 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPhone 13 / iPhone 13 Pro / iPhone 12 / iPhone 12 Pro]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 375 && _screenLogicalHeight == 812 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPhone 13 mini / iPhone 12 mini / iPhone 11 Pro / iPhone XS / iPhone X]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 428 && _screenLogicalHeight == 926 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPhone 13 Pro Max / iPhone 12 Pro Max]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 375 && _screenLogicalHeight == 667 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPhone SE 2nd gen / iPhone 8 / iPhone 7 / iPhone 6s / iPhone 6]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 414 && _screenLogicalHeight == 896 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPhone 11 Pro Max / iPhone 11 / iPhone XR / iPhone XS Max]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 414 && _screenLogicalHeight == 736 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPhone 8 Plus]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 476 && _screenLogicalHeight == 847 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPhone 7 Plus / iPhone 6s Plus / iPhone 6 Plus]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 320 && _screenLogicalHeight == 568 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPhone SE 1st gen / iPhone 5C / iPhone 5S / iPhone 5 / iPod touch 6th gen / iPod touch 5th gen]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 320 && _screenLogicalHeight == 480 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPhone 4S / iPhone 4 / iPhone 3GS / iPhone 3G / iPhone 1st gen / iPod touch 4th gen]")
            print("[Device :: iPod touch 3rd gen / iPod touch 2nd gen / iPod touch 1st gen]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 744 && _screenLogicalHeight == 1133 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPad Mini (6th gen)]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 810 && _screenLogicalHeight == 1080 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPad 9th gen / iPad 8th gen / iPad 7th gen]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 1024 && _screenLogicalHeight == 1366 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPad Pro (5th gen 12.9) / iPad Pro (4th gen 12.9) / iPad Pro (3rd gen 12.9) / iPad Pro (2nd gen 12.9)]")
            print("[Device :: iPad Pro (1st gen 12.9)]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 834 && _screenLogicalHeight == 1194 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPad Pro (5th gen 11) / iPad Pro (4th gen 11) / iPad Pro (3rd gen 11)]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 820 && _screenLogicalHeight == 1180 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPad Air (4th gen)]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 768 && _screenLogicalHeight == 1024 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPad Mini (5th gen) / iPad 6th gen / iPad 5th gen / iPad Pro (1st gen 9.7)]")
            print("[Device :: iPad mini 4 / iPad Air 2 / iPad mini 3 / iPad mini 2 / iPad Air]")
            print("[Device :: iPad 4th gen / iPad mini / iPad 3rd gen / iPad 2 / iPad 1st gen]")
            print("===============================")
            print("")
        }
        else if _screenLogicalWidth == 834 && _screenLogicalHeight == 1112 {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: iPad Air (3rd gen) / iPad Pro (2nd gen 10.5)]")
            print("===============================")
            print("")
        }
        else {
            print("")
            print("===============================")
            print("[ViewController >> checkDisplay() :: 디바이스 종류 확인]")
            print("[Device :: ELSE]")
            print("===============================")
            print("")
        }
    }

 


[결과 출력]


 

반응형
Comments