userInterfaceIdiom returning wrong values on real devices

My app was rejected because there is a problem on the iPad UI of my app. I have fixed it before this getting rejected by checking if the device was an iPad to make some minor adjustments to the UI measures. The problem is that when I call:

UIDevice.currentDevice().userInterfaceIdiom //returns .Unspecified
traitCollection.userInterfaceIdiom //returns -1

On a real iPad I get .Unspecified. Why is this?

Answers


In order to fix this I have created a custom method which actually works on a 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 where value != 0 else { return identifier }
        return identifier + String(UnicodeScalar(UInt8(value)))
    }

    return identifier
}

}

In order to use it call

UIDevice.currentDevice().isIpadDevice() //wohoo

Need Your Help

Rails date format in a text_field

ruby-on-rails

I have a rails form that displays a date in a text_field:

GPRS connection still connected while receiving phone call?

android

Suppose one application is running which is using GPRS connection. If in between that if call comes what will happened with that GPRS connection?? It still persist or it is get disconnected??