6
6
//
7
7
8
8
import Foundation
9
- import UIKit
9
+
10
+ fileprivate func processInfoOperationSystemVersion( ) -> String {
11
+ let version = ProcessInfo ( ) . operatingSystemVersion
12
+ return " \( version. majorVersion) . \( version. minorVersion) . \( version. patchVersion) "
13
+ }
14
+
15
+ fileprivate func posixModelName( ) -> String {
16
+ var systemName = utsname ( )
17
+ uname ( & systemName)
18
+ return withUnsafePointer ( to: & systemName. machine) {
19
+ $0. withMemoryRebound ( to: CChar . self, capacity: 1 ) {
20
+ ptr in String . init ( validatingUTF8: ptr)
21
+ }
22
+ } ?? " Unknown "
23
+ }
24
+
25
+ fileprivate func inferredPlatformName( ) -> String {
26
+ let modelName = posixModelName ( )
27
+ if modelName. contains ( " ipad " ) {
28
+ return " iPadOS "
29
+ } else if modelName. contains ( " iphone " ) {
30
+ return " iOS "
31
+ } else {
32
+ #if targetEnvironment(simulator)
33
+ return " Simulator "
34
+ #else
35
+ return " Unknown "
36
+ #endif
37
+ }
38
+ }
10
39
11
40
class Reporter : NSObject {
12
41
@@ -28,9 +57,11 @@ class Reporter: NSObject {
28
57
var locale : Locale {
29
58
Locale . current
30
59
}
31
- var device : UIDevice {
32
- UIDevice . current
33
- }
60
+
61
+ let model : String
62
+ let platformName : String
63
+ let platformVersion : String
64
+
34
65
var regionCode : String ? {
35
66
if #available( iOS 16 , * ) {
36
67
return locale. language. region? . identifier
@@ -52,6 +83,10 @@ class Reporter: NSObject {
52
83
string: " https://mobile.muxanalytics.com "
53
84
) !
54
85
86
+ self . model = posixModelName ( )
87
+ self . platformName = inferredPlatformName ( )
88
+ self . platformVersion = processInfoOperationSystemVersion ( )
89
+
55
90
super. init ( )
56
91
57
92
let sessionConfig : URLSessionConfiguration = URLSessionConfiguration . default
@@ -105,12 +140,12 @@ extension Reporter {
105
140
let data = UploadSucceededEvent . Data (
106
141
appName: Bundle . main. appName,
107
142
appVersion: Bundle . main. appVersion,
108
- deviceModel: device . model,
143
+ deviceModel: model,
109
144
inputDuration: inputDuration,
110
145
inputSize: inputSize,
111
146
inputStandardizationRequested: options. inputStandardization. isRequested,
112
- platformName: device . systemName ,
113
- platformVersion: device . systemVersion ,
147
+ platformName: platformName ,
148
+ platformVersion: platformVersion ,
114
149
regionCode: regionCode,
115
150
sdkVersion: Version . versionString,
116
151
uploadStartTime: uploadStartTime,
@@ -145,13 +180,13 @@ extension Reporter {
145
180
let data = UploadFailedEvent . Data (
146
181
appName: Bundle . main. appName,
147
182
appVersion: Bundle . main. appVersion,
148
- deviceModel: device . model,
183
+ deviceModel: model,
149
184
errorDescription: errorDescription,
150
185
inputDuration: inputDuration,
151
186
inputSize: inputSize,
152
187
inputStandardizationRequested: options. inputStandardization. isRequested,
153
- platformName: device . systemName ,
154
- platformVersion: device . systemVersion ,
188
+ platformName: platformName ,
189
+ platformVersion: platformVersion ,
155
190
regionCode: regionCode,
156
191
sdkVersion: Version . versionString,
157
192
uploadStartTime: uploadStartTime,
@@ -186,13 +221,13 @@ extension Reporter {
186
221
let data = InputStandardizationSucceededEvent . Data (
187
222
appName: Bundle . main. appName,
188
223
appVersion: Bundle . main. appVersion,
189
- deviceModel: device . model,
224
+ deviceModel: model,
190
225
inputDuration: inputDuration,
191
226
inputSize: inputSize,
192
227
maximumResolution: options. inputStandardization. maximumResolution. description,
193
228
nonStandardInputReasons: nonStandardInputReasons. map ( \. description) ,
194
- platformName: device . systemName ,
195
- platformVersion: device . systemVersion ,
229
+ platformName: platformName ,
230
+ platformVersion: platformVersion ,
196
231
regionCode: regionCode,
197
232
sdkVersion: Version . versionString,
198
233
standardizationStartTime: standardizationStartTime,
@@ -229,14 +264,14 @@ extension Reporter {
229
264
let data = InputStandardizationFailedEvent . Data (
230
265
appName: Bundle . main. appName,
231
266
appVersion: Bundle . main. appVersion,
232
- deviceModel: device . model,
267
+ deviceModel: model,
233
268
errorDescription: errorDescription,
234
269
inputDuration: inputDuration,
235
270
inputSize: inputSize,
236
271
maximumResolution: options. inputStandardization. maximumResolution. description,
237
272
nonStandardInputReasons: nonStandardInputReasons. map ( \. description) ,
238
- platformName: device . systemName ,
239
- platformVersion: device . systemVersion ,
273
+ platformName: platformName ,
274
+ platformVersion: platformVersion ,
240
275
regionCode: regionCode,
241
276
sdkVersion: Version . versionString,
242
277
standardizationStartTime: standardizationStartTime,
0 commit comments