Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
main ▾

xtool.git / Sources / XKit / DeveloperServices / Devices / DeveloperServicesAddDeviceOperation.swift

DeveloperServicesAddDeviceOperation.swift36 lines · 1.1 KiBRaw
1import Foundation
2import DeveloperAPI
3
4public struct DeveloperServicesAddDeviceOperation: DeveloperServicesOperation {
5 public let context: SigningContext
6 public init(context: SigningContext) {
7 self.context = context
8 }
9
10 public func perform() async throws {
11 guard let targetDevice = context.targetDevice else { return }
12
13 // try to register the device
14 let response = try await context.developerAPIClient.devicesCreateInstance(
15 body: .json(.init(data: .init(
16 _type: .devices,
17 attributes: .init(
18 name: targetDevice.name,
19 platform: .init(.ios),
20 udid: targetDevice.udid
21 )
22 )))
23 )
24
25 // we get a 409 CONFLICT if the device was already registered.
26 // handle this by returning gracefully.
27 if (try? response.conflict) != nil {
28 return
29 }
30
31 // otherwise, we should get a 201 CREATED to indicate that the device
32 // was added. any other case is unexpected, and this will throw.
33 _ = try response.created
34 }
35
36}