iOS 개발 기록

[iOS] Device Model 체크 본문

iOS

[iOS] Device Model 체크

택꽁이 2023. 2. 6. 13:13
728x90

DeviceModel 체크

코드

func deviceModelName() -> String {
      // 실제 디바이스 체크
      let device = UIDevice.current
      let selName = "_\("deviceInfo")ForKey:"
      let selector = NSSelectorFromString(selName)
      if device.responds(to: selector) {
        let modelName = String(describing: device.perform(selector, with: "marketing-name").takeRetainedValue())
        return modelName
      }

      // 시뮬레이터 체크
      if let modelName = ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"],
          modelName.count > 0 {
        return modelName
      }

      return "unknowned device"
    }

Machine Code

https://gist.github.com/adamawolf/3048717