-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSessionDetails.swift
More file actions
37 lines (33 loc) · 1.31 KB
/
SessionDetails.swift
File metadata and controls
37 lines (33 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Foundation
public struct SessionDetails {
let deviceId: String
let platform: String
let buildNumber: String
let marketingVersion: String
let identifier: String
let osVersion: String
}
extension SessionDetails: Encodable {
enum CodingKeys: String, CodingKey {
case deviceId = "device_id"
case platform = "platform"
case buildNumber = "build_number"
case marketingVersion = "marketing_version"
case identifier = "identifier"
case osVersion = "os_version"
}
init(deviceId: String, bundle: Bundle = .main) {
self.deviceId = deviceId
self.platform = "ios"
self.buildNumber = bundle.infoDictionary?["CFBundleVersion"] as? String ?? "Unknown"
self.marketingVersion = bundle.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown"
self.identifier = bundle.bundleIdentifier ?? "Unknown"
let version = ProcessInfo.processInfo.operatingSystemVersion
self.osVersion = "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)"
}
func dictionaryRepresentation() throws -> [String: AnyObject]? {
let encoder = JSONEncoder()
let data = try encoder.encode(self)
return try JSONSerialization.jsonObject(with: data) as? [String: AnyObject]
}
}