ios - userInterfaceIdiom returning wrong values on real devices -


my app rejected because there problem on ipad ui of app. have fixed before getting rejected checking if device ipad make minor adjustments ui measures. problem when call:

uidevice.currentdevice().userinterfaceidiom //returns .unspecified traitcollection.userinterfaceidiom //returns -1 

on real ipad .unspecified. why this?

in order fix have created custom method works on real ipad

public extension uidevice {  func isipaddevice() -> bool {     let identifier = deviceidentifier()      return identifier.lowercasestring.containsstring("ipad") }  private func deviceidentifier() -> string {     var systeminfo = utsname()     uname(&systeminfo)     let machinemirror = mirror(reflecting: systeminfo.machine)     let identifier = machinemirror.children.reduce("") { identifier, element in         guard let value = element.value as? int8 value != 0 else { return identifier }         return identifier + string(unicodescalar(uint8(value)))     }      return identifier } 

}

in order use call

uidevice.currentdevice().isipaddevice() //wohoo 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -