UIDevice

class UIDevice : NSObject

This extesion adds some useful functions to UIDevice

  • Get OS version string.

    Declaration

    Swift

    public static var osVersion: String { get }
  • Returns OS version without subversions.

    Example: 9.

    Declaration

    Swift

    public static var osMajorVersion: Int { get }
  • Returns device platform string.

    Example: iPhone7,2.

    Declaration

    Swift

    public static var hardwareModel: String { get }

    Return Value

    Returns the device platform string.

  • Returns the user-friendly device platform string. More info here.

    Example: iPad Air (Cellular).

    Declaration

    Swift

    public static var detailedModel: String { get }

    Return Value

    Returns the user-friendly device platform string.

  • Returns current device CPU frequency.

    Declaration

    Swift

    public static var cpuFrequency: Int { get }
  • Returns current device BUS frequency.

    Declaration

    Swift

    public static var busFrequency: Int { get }
  • Returns device RAM size.

    Declaration

    Swift

    public static var ramSize: Int { get }
  • Returns device CPUs number.

    Declaration

    Swift

    public static var cpusNumber: Int { get }
  • Returns device total memory.

    Declaration

    Swift

    public static var totalMemory: Int { get }
  • Returns current device non-kernel memory.

    Declaration

    Swift

    public static var userMemory: Int { get }
  • Undocumented

    Declaration

    Swift

    public static var isLowPowerModeEnabled: Bool { get }
  • Undocumented

    Declaration

    Swift

    @objc
    public static func lowPowerModeChanged(_ block: @escaping (_ isLowPowerModeEnabled: Bool) -> Void)
  • Check if current device is an iPhone.

    Declaration

    Swift

    public static func isPhone() -> Bool

    Return Value

    Returns true if it is an iPhone, otherwise false.

  • Check if current device is an iPad.

    Declaration

    Swift

    public static func isPad() -> Bool

    Return Value

    Returns true if it is an iPad, otherwise false.

  • Check if current device is an iPod.

    Declaration

    Swift

    public static func isPod() -> Bool

    Return Value

    Returns true if it is an iPod, otherwise false.

  • Check if current device is an Apple TV.

    Declaration

    Swift

    public static func isTV() -> Bool

    Return Value

    Returns true if it is an Apple TV, otherwise false.

  • Check if current device is an Applw Watch.

    Declaration

    Swift

    public static func isWatch() -> Bool

    Return Value

    Returns true if it is an Apple Watch, otherwise false.

  • Check if current device is a Simulator.

    Declaration

    Swift

    public static func isSimulator() -> Bool

    Return Value

    Returns true if it is a Simulator, otherwise false.

  • Returns if current device is jailbroken.

    Declaration

    Swift

    public static func isJailbroken() -> Bool

    Return Value

    Returns true if current device is jailbroken, otherwise false.

  • Returns system uptime.

    Declaration

    Swift

    public static func uptime() -> TimeInterval

    Return Value

    eturns system uptime.

  • Returns sysyem uptime as Date.

    Declaration

    Swift

    public static func uptimeDate() -> Date

    Return Value

    Returns sysyem uptime as Date.

  • Returns current device total disk space

    Declaration

    Swift

    public static func totalDiskSpace() -> NSNumber

    Return Value

    Returns current device total disk space.

  • Returns current device free disk space.

    Declaration

    Swift

    public static func freeDiskSpace() -> NSNumber

    Return Value

    Returns current device free disk space.

  • When save is false, a new UUID will be created every time. When save is true, a new UUID will be created and saved in the user defatuls. It will be retrieved on next calls.

    Declaration

    Swift

    public static func generateUniqueIdentifier(save: Bool = false, force: Bool = false) -> String

    Parameters

    save

    If true the UUID will be saved, otherview not.

    force

    If true a new UUID will be forced, even there is a saved one.

    Return Value

    Returns the created (save = false) or retrieved (save` = true) UUID String.

  • Save the unique identifier or update it if there is and it is changed. Is useful for push notification to know if the unique identifier has changed and needs to be sent to server.

    Declaration

    Swift

    public static func saveAPNSIdentifier(_ uniqueIdentifier: Any, completion: @escaping (_ isValid: Bool, _ needsUpdate: Bool, _ oldUUID: String?, _ newUUID: String) -> Void)

    Parameters

    uniqueIdentifier

    The unique identifier to save or update if needed. Must be Data or String type.

    completion

    The execution block that know if the unique identifier is valid and has to be updated. You have to handle the case if it is valid and the update is needed or not.

    isValid

    Returns if the APNS token is valid.

    needsUpdate

    Returns if the APNS token needsAnUpdate.

    oldUUID

    Returns the old UUID, if present. May be nil.

    newUUID

    Returns the new UUID.