Created
July 10, 2016 09:15
-
-
Save Blackjacx/8a289fe47a4d3430c59505bc254797aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static func deviceAndVersionSpecificInformationAsString(userID: String?) -> String { | |
let processInfo = NSProcessInfo() | |
let byteCountFormatter = NSByteCountFormatter() | |
var data = Array<String>() | |
var systemComponents = Array<String>() | |
byteCountFormatter.countStyle = .Memory | |
byteCountFormatter.allowsNonnumericFormatting = false | |
data.append(UIDevice.versionString()) | |
if let uid = userID { | |
data.append("UID: \(uid)") | |
} else { | |
data.append("UID: -") | |
} | |
if let platformRawString = UIDevice.platformRawString() { | |
systemComponents.append(platformRawString) | |
} | |
systemComponents.append("iOS \(processInfo.operatingSystemVersionString)") | |
data.append("System: \(systemComponents.joinWithSeparator(" - "))") | |
let batteryLevelName = NSLocalizedString(Constants.kEmailBatteryLevelText, comment: "String used in email body for the battery level") | |
data.append(String(format: "%@: %zd%%", batteryLevelName, UIDevice.batteryLevelInPercent())) | |
let processorCountName = NSLocalizedString(Constants.kEmailProcessorCountText, comment: "String used in email body for the processor count") | |
data.append("\(processorCountName): \(processInfo.processorCount)") | |
let physicalMemoryName = NSLocalizedString(Constants.kEmailPhysicalMemoryText, comment: "String used in email body for the physical memory") | |
let physicalMemory = byteCountFormatter.stringFromByteCount(Int64(processInfo.physicalMemory)) | |
data.append("\(physicalMemoryName): \(physicalMemory)") | |
let uptimeName = NSLocalizedString(Constants.kEmailUptimeText, comment: "String used in email body for the physical memory") | |
let dateComponentsFormatter = NSDateComponentsFormatter() | |
dateComponentsFormatter.unitsStyle = .Abbreviated | |
dateComponentsFormatter.maximumUnitCount = 2 | |
let uptime = dateComponentsFormatter.stringFromTimeInterval(processInfo.systemUptime) | |
data.append("\(uptimeName): \(uptime!)") | |
let freeDiskSpaceName = NSLocalizedString(Constants.kEmailFreeDiskSpaceText, comment: "String used in email body for the physical memory") | |
var freeDiskSpace = byteCountFormatter.stringFromByteCount(0) | |
if let diskSpace = UIDevice.deviceRemainingFreeSpaceInBytes() { | |
freeDiskSpace = byteCountFormatter.stringFromByteCount(diskSpace) | |
} | |
data.append("\(freeDiskSpaceName): \(freeDiskSpace)") | |
return "\n\n\n---\n\(data.joinWithSeparator("\n"))" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment