diff --git a/Config/CommonConfiguration.swift b/Config/CommonConfiguration.swift
index 5937b46590..6f9a7f555b 100644
--- a/Config/CommonConfiguration.swift
+++ b/Config/CommonConfiguration.swift
@@ -17,6 +17,10 @@
import Foundation
import MatrixSDK
+#if !os(OSX)
+import DeviceKit
+#endif
+
/// CommonConfiguration is the central point to setup settings for MatrixSDK, MatrixKit and common configurations for all targets.
class CommonConfiguration: NSObject, Configurable {
@@ -66,8 +70,13 @@ class CommonConfiguration: NSObject, Configurable {
// Disable identicon use
sdkOptions.disableIdenticonUseForUserAvatar = true
+ // Set up user agent
+ if let userAgent = makeASCIIUserAgent() {
+ sdkOptions.httpAdditionalHeaders = ["User-Agent": userAgent]
+ }
+
// Pass httpAdditionalHeaders to the SDK
- sdkOptions.httpAdditionalHeaders = BuildSettings.httpAdditionalHeaders
+ sdkOptions.httpAdditionalHeaders = (sdkOptions.httpAdditionalHeaders ?? [:]).merging(BuildSettings.httpAdditionalHeaders, uniquingKeysWith: { _, value in value })
// Disable key backup on common
sdkOptions.enableKeyBackupWhenStartingMXCrypto = false
@@ -82,6 +91,59 @@ class CommonConfiguration: NSObject, Configurable {
MXKeyProvider.sharedInstance().delegate = EncryptionKeyManager.shared
}
+ private func makeASCIIUserAgent() -> String? {
+ guard var userAgent = makeUserAgent() else {
+ return nil
+ }
+ if !userAgent.canBeConverted(to: .ascii) {
+ let mutableUserAgent = NSMutableString(string: userAgent)
+ if CFStringTransform(mutableUserAgent, nil, "Any-Latin; Latin-ASCII; [:^ASCII:] Remove" as CFString, false) {
+ userAgent = mutableUserAgent as String
+ }
+ }
+ return userAgent
+ }
+
+ private func makeUserAgent() -> String? {
+ let appInfo = AppInfo.current
+ let clientName = appInfo.displayName
+ let clientVersion = appInfo.appVersion?.bundleShortVersion ?? "unknown"
+
+ #if os(iOS)
+ return String(
+ format: "%@/%@ (%@; iOS %@; Scale/%0.2f)",
+ clientName,
+ clientVersion,
+ Device.current.safeDescription,
+ UIDevice.current.systemVersion,
+ UIScreen.main.scale)
+ #elseif os(tvOS)
+ return String(
+ format: "%@/%@ (%@; tvOS %@; Scale/%0.2f)",
+ clientName,
+ clientVersion,
+ Device.current.safeDescription,
+ UIDevice.current.systemVersion,
+ UIScreen.main.scale)
+ #elseif os(watchOS)
+ return String(
+ format: "%@/%@ (%@; watchOS %@; Scale/%0.2f)",
+ clientName,
+ clientVersion,
+ Device.current.safeDescription,
+ WKInterfaceDevice.current.systemVersion,
+ WKInterfaceDevice.currentDevice.screenScale)
+ #elseif os(OSX)
+ return String(
+ format: "%@/%@ (Mac; Mac OS X %@)",
+ clientName,
+ clientVersion,
+ NSProcessInfo.processInfo.operatingSystemVersionString)
+ #else
+ return nil
+ #endif
+ }
+
// MARK: - Per matrix session settings
diff --git a/Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved
index 3d248ff515..7b45c9e98f 100644
--- a/Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved
+++ b/Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved
@@ -1,5 +1,14 @@
{
"pins" : [
+ {
+ "identity" : "devicekit",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/devicekit/DeviceKit",
+ "state" : {
+ "revision" : "20e0991f3975916ab0f6d58db84d8bc64f883537",
+ "version" : "4.7.0"
+ }
+ },
{
"identity" : "maplibre-gl-native-distribution",
"kind" : "remoteSourceControl",
diff --git a/Riot/Assets/third_party_licenses.html b/Riot/Assets/third_party_licenses.html
index a9365018fe..ebd5e6b119 100644
--- a/Riot/Assets/third_party_licenses.html
+++ b/Riot/Assets/third_party_licenses.html
@@ -1908,6 +1908,32 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+