Skip to content

Commit

Permalink
chore: bump ios-Core
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Sep 4, 2023
1 parent 6fd272d commit 288f6b2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core",
"state" : {
"revision" : "36296ffafcb03b382d2bc9eb060cba0b27a69e40"
"revision" : "73a982d892ce19966f7393f2093a1f0cc7731838"
}
},
{
Expand Down
63 changes: 0 additions & 63 deletions MailCore/API/MailApiFetcher/MailApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,72 +21,9 @@ import Foundation
import InfomaniakCore
import InfomaniakDI
import InfomaniakLogin
import MachO
import Sentry
import UIKit

// TODO: move to Core and share with kDrive
/// Something to construct a standard Infomaniak User-Agent
public struct UserAgentBuilder {
func modelIdentifier() -> String? {
if let simulatorModelIdentifier = ProcessInfo()
.environment["SIMULATOR_MODEL_IDENTIFIER"] { return simulatorModelIdentifier }
var sysinfo = utsname()
uname(&sysinfo) // ignore return value
return String(bytes: Data(bytes: &sysinfo.machine,
count: Int(_SYS_NAMELEN)), encoding: .ascii)?
.trimmingCharacters(in: .controlCharacters)
}

func microarchitecture() -> String? {
guard let archRaw = NXGetLocalArchInfo().pointee.name else {
return nil
}
return String(cString: archRaw)
}

/// The standard infomaniak app user agent
public var userAgent: String {
let release = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "x.x.x"
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "x"

let executableName = Bundle.main.bundleIdentifier ?? "com.infomaniak.x"
let appVersion = "\(release)-\(build)"
let hardwareDevice = modelIdentifier() ?? "unknownModel"

let operatingSystemVersion = ProcessInfo.processInfo.operatingSystemVersion
let OSNameAndVersion =
"\(UIDevice.current.systemName) \(operatingSystemVersion.majorVersion).\(operatingSystemVersion.minorVersion).\(operatingSystemVersion.patchVersion)"

let cpuArchitecture = microarchitecture() ?? "unknownArch"

/// Something like:
/// `com.infomaniak.mail/1.0.5-1 (iPhone15,2; iOS16.4.0; arm64e)`
/// `com.infomaniak.mail.ShareExtension/1.0.5-1 (iPhone15,2; iOS16.4.0; arm64e)`
let userAgent = "\(executableName)/\(appVersion) (\(hardwareDevice); \(OSNameAndVersion); \(cpuArchitecture))"
return userAgent
}
}

/// Something to set the user agent for AF requests
public class UserAgentAdapter: RequestAdapter {
public static let userAgentKey = "User-Agent"

public init() {}

public func adapt(
_ urlRequest: URLRequest,
for session: Alamofire.Session,
completion: @escaping (Result<URLRequest, Error>) -> Void
) {
var adaptedRequest = urlRequest
adaptedRequest.headers.remove(name: Self.userAgentKey)
adaptedRequest.headers.add(name: Self.userAgentKey, value: UserAgentBuilder().userAgent)

completion(.success(adaptedRequest))
}
}

public extension ApiFetcher {
convenience init(token: ApiToken, delegate: RefreshTokenDelegate) {
self.init()
Expand Down
2 changes: 1 addition & 1 deletion Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let project = Project(name: "Mail",
.package(url: "https://github.com/Infomaniak/ios-dependency-injection", .upToNextMajor(from: "1.1.6")),
.package(
url: "https://github.com/Infomaniak/ios-core",
.revision("36296ffafcb03b382d2bc9eb060cba0b27a69e40")
.revision("73a982d892ce19966f7393f2093a1f0cc7731838")
),
.package(url: "https://github.com/Infomaniak/ios-core-ui", .upToNextMajor(from: "2.5.3")),
.package(url: "https://github.com/Infomaniak/ios-notifications", .upToNextMajor(from: "3.0.0")),
Expand Down

0 comments on commit 288f6b2

Please sign in to comment.