Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove UIKit dependency #90

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 51 additions & 16 deletions Sources/MuxUploadSDK/InternalUtilities/Reporting/Reporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,36 @@
//

import Foundation
import UIKit

fileprivate func processInfoOperationSystemVersion() -> String {
let version = ProcessInfo().operatingSystemVersion
return "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)"
}

fileprivate func posixModelName() -> String {
var systemName = utsname()
uname(&systemName)
return withUnsafePointer(to: &systemName.machine) {
$0.withMemoryRebound(to: CChar.self, capacity: 1) {
ptr in String.init(validatingUTF8: ptr)
}
} ?? "Unknown"
}

fileprivate func inferredPlatformName() -> String {
let modelName = posixModelName()
if modelName.contains("ipad") {
return "iPadOS"
} else if modelName.contains("iphone") {
return "iOS"
} else {
#if targetEnvironment(simulator)
return "Simulator"
#else
return "Unknown"
#endif
}
}

class Reporter: NSObject {

Expand All @@ -28,9 +57,11 @@ class Reporter: NSObject {
var locale: Locale {
Locale.current
}
var device: UIDevice {
UIDevice.current
}

let model: String
let platformName: String
let platformVersion: String

var regionCode: String? {
if #available(iOS 16, *) {
return locale.language.region?.identifier
Expand All @@ -52,6 +83,10 @@ class Reporter: NSObject {
string: "https://mobile.muxanalytics.com"
)!

self.model = posixModelName()
self.platformName = inferredPlatformName()
self.platformVersion = processInfoOperationSystemVersion()

super.init()

let sessionConfig: URLSessionConfiguration = URLSessionConfiguration.default
Expand Down Expand Up @@ -105,12 +140,12 @@ extension Reporter {
let data = UploadSucceededEvent.Data(
appName: Bundle.main.appName,
appVersion: Bundle.main.appVersion,
deviceModel: device.model,
deviceModel: model,
inputDuration: inputDuration,
inputSize: inputSize,
inputStandardizationRequested: options.inputStandardization.isRequested,
platformName: device.systemName,
platformVersion: device.systemVersion,
platformName: platformName,
platformVersion: platformVersion,
regionCode: regionCode,
sdkVersion: Version.versionString,
uploadStartTime: uploadStartTime,
Expand Down Expand Up @@ -145,13 +180,13 @@ extension Reporter {
let data = UploadFailedEvent.Data(
appName: Bundle.main.appName,
appVersion: Bundle.main.appVersion,
deviceModel: device.model,
deviceModel: model,
errorDescription: errorDescription,
inputDuration: inputDuration,
inputSize: inputSize,
inputStandardizationRequested: options.inputStandardization.isRequested,
platformName: device.systemName,
platformVersion: device.systemVersion,
platformName: platformName,
platformVersion: platformVersion,
regionCode: regionCode,
sdkVersion: Version.versionString,
uploadStartTime: uploadStartTime,
Expand Down Expand Up @@ -186,13 +221,13 @@ extension Reporter {
let data = InputStandardizationSucceededEvent.Data(
appName: Bundle.main.appName,
appVersion: Bundle.main.appVersion,
deviceModel: device.model,
deviceModel: model,
inputDuration: inputDuration,
inputSize: inputSize,
maximumResolution: options.inputStandardization.maximumResolution.description,
nonStandardInputReasons: nonStandardInputReasons.map(\.description),
platformName: device.systemName,
platformVersion: device.systemVersion,
platformName: platformName,
platformVersion: platformVersion,
regionCode: regionCode,
sdkVersion: Version.versionString,
standardizationStartTime: standardizationStartTime,
Expand Down Expand Up @@ -229,14 +264,14 @@ extension Reporter {
let data = InputStandardizationFailedEvent.Data(
appName: Bundle.main.appName,
appVersion: Bundle.main.appVersion,
deviceModel: device.model,
deviceModel: model,
errorDescription: errorDescription,
inputDuration: inputDuration,
inputSize: inputSize,
maximumResolution: options.inputStandardization.maximumResolution.description,
nonStandardInputReasons: nonStandardInputReasons.map(\.description),
platformName: device.systemName,
platformVersion: device.systemVersion,
platformName: platformName,
platformVersion: platformVersion,
regionCode: regionCode,
sdkVersion: Version.versionString,
standardizationStartTime: standardizationStartTime,
Expand Down