-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve user-agent with more detail (#74)
* adding user agent * can import UIKit * Minor fix * conditional import statements * minor fix for deviceInfo. Need to discuss for the 'default value' in case UIKit is unavailable * added test case and comments
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Foundation | ||
#if canImport(UIKit) | ||
import UIKit | ||
|
||
internal enum DeviceInfo { | ||
/// Device's model on which SDK is running eg. iPhone12,3 | ||
static let deviceInfo: String = UIDevice.deviceModelCode | ||
/// Operating system and version of OS of the Device | ||
static let osInfo : String = "\(UIDevice().systemName) \(UIDevice().systemVersion)" | ||
/// Name of customer's application using the SDK | ||
static let customerAppName : String = Bundle.main.infoDictionary?["CFBundleName"] as? String ?? "" | ||
/// Version of the customer's application using the SDK | ||
static let customerAppVersion : String = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "" | ||
} | ||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Foundation | ||
#if canImport(UIKit) | ||
import UIKit | ||
|
||
|
||
/** | ||
Extend `UIDevice` to get user's device information such as | ||
device's model. If running on Simulator `deviceModelCode` | ||
will return values like`x86_64` but when running on a device, this function | ||
returns exact device model for example, `iPhone12,3` | ||
|
||
Use case : | ||
To get model detail, simply use | ||
|
||
let deviceModelInfo = UIDevice.deviceModelCode | ||
*/ | ||
public extension UIDevice { | ||
|
||
static let deviceModelCode : String = { | ||
|
||
var systemInfo = utsname() | ||
uname(&systemInfo) | ||
let machineMirror = Mirror(reflecting: systemInfo.machine) | ||
let identifier = machineMirror.children.reduce("") { identifier, element in | ||
guard let value = element.value as? Int8, value != 0 else { return identifier } | ||
return identifier + String(UnicodeScalar(UInt8(value))) | ||
} | ||
return identifier | ||
}() | ||
} | ||
#endif |
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
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