Skip to content

Commit 5b6babb

Browse files
authored
Merge pull request #31 from appwrite/dev
Fix tvos and watchos
2 parents dc0849e + 5f7b1d5 commit 5b6babb

28 files changed

+1121
-856
lines changed

Package.resolved

Lines changed: 0 additions & 88 deletions
This file was deleted.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
platforms: [
88
.iOS("15.0"),
99
.macOS("11.0"),
10-
.watchOS("6.0"),
10+
.watchOS("7.0"),
1111
.tvOS("13.0"),
1212
],
1313
products: [

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-apple.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-apple.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-1.2.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.2.1-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
88
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
@@ -19,7 +19,7 @@ Appwrite is an open-source backend as a service server that abstract and simplif
1919

2020
The Appwrite Swift SDK is available via Swift Package Manager. In order to use the Appwrite Swift SDK from Xcode, select File > **Add Packages**
2121

22-
In the dialog that appears, enter the Appwrite Swift SDK [package URL](git@github.com:appwrite/sdk-for-apple.git) in the search field. Once found, select `sdk-for-apple`.
22+
In the dialog that appears, enter the Appwrite Swift SDK [package URL](https://github.com/appwrite/sdk-for-apple.git) in the search field. Once found, select `sdk-for-apple`.
2323

2424
On the right, select your version rules and ensure your desired target is selected in the **Add to Project** field.
2525

@@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:
3131

3232
```swift
3333
dependencies: [
34-
.package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "1.2.2"),
34+
.package(url: "https://github.com/appwrite/sdk-for-apple.git", from: "1.2.3"),
3535
],
3636
```
3737

Sources/Appwrite/Client.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class Client {
2323
"x-sdk-name": "Apple",
2424
"x-sdk-platform": "client",
2525
"x-sdk-language": "apple",
26-
"x-sdk-version": "1.2.2",
26+
"x-sdk-version": "1.2.3",
2727
"X-Appwrite-Response-Format": "1.0.0"
2828
]
2929

@@ -582,10 +582,10 @@ extension Client {
582582
device = "\(info!.modelIdentifier) iOS/\(info!.systemVersion)"
583583
#elseif os(watchOS)
584584
let info = deviceInfo.watchOSInfo
585-
device = "\(info!.systemInfo.machine) watchOS/\(info!.systemVersion)"
585+
device = "\(info!.modelIdentifier) watchOS/\(info!.systemVersion)"
586586
#elseif os(tvOS)
587-
let info = deviceInfo.tvOSInfo
588-
device = "\(info!.systemInfo.machine) tvOS/\(info!.systemVersion)"
587+
let info = deviceInfo.iOSInfo
588+
device = "\(info!.modelIdentifier) tvOS/\(info!.systemVersion)"
589589
#elseif os(macOS)
590590
let info = deviceInfo.macOSInfo
591591
device = "(Macintosh; \(info!.model))"
Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#if os(Linux)
22
import Foundation
33

4-
class LinuxDeviceInfo : DeviceInfo {
4+
class LinuxDeviceInfo {
55

66
let name: String
77
let version: String
@@ -14,53 +14,24 @@ class LinuxDeviceInfo : DeviceInfo {
1414
let variant: String
1515
let variantId: String
1616
let machineId: String
17-
18-
internal init(
19-
name: String,
20-
version: String,
21-
id: String,
22-
idLike: [String],
23-
versionCodename: String,
24-
versionId: String,
25-
prettyName: String,
26-
buildId: String,
27-
variant: String,
28-
variantId: String,
29-
machineId: String
30-
) {
31-
self.name = name
32-
self.version = version
33-
self.id = id
34-
self.idLike = idLike
35-
self.versionCodename = versionCodename
36-
self.versionId = versionId
37-
self.prettyName = prettyName
38-
self.buildId = buildId
39-
self.variant = variant
40-
self.variantId = variantId
41-
self.machineId = machineId
42-
}
43-
44-
public static func get() -> LinuxDeviceInfo {
45-
let os = getOsRelease()
46-
let lsb = getLsbRelease()
47-
let machineId = getMachineId()
48-
49-
return LinuxDeviceInfo(
50-
name: os["NAME"] ?? "Linux",
51-
version: os["VERSION"] ?? lsb["LSB_VERSION"] ?? "",
52-
id: os["ID"] ?? lsb["DISTRIB_ID"] ?? "linux",
53-
idLike: os["ID_LIKE"]?.split(separator: " ").map { String($0) } ?? [],
54-
versionCodename: os["VERSION_CODENAME"] ?? lsb["DISTRIB_CODENAME"] ?? "",
55-
versionId: os["VERSION_ID"] ?? lsb["DISTRIB_RELEASE"] ?? "",
56-
prettyName: os["PRETTY_NAME"] ?? lsb["DISTRIB_DESCRIPTION"] ?? "Linux",
57-
buildId: os["BUILD_ID"] ?? "",
58-
variant: os["VARIANT"] ?? "",
59-
variantId: os["VARIANT_ID"] ?? "",
60-
machineId: machineId
61-
)
17+
18+
public init() {
19+
let os = LinuxDeviceInfo.getOsRelease()
20+
let lsb = LinuxDeviceInfo.getLsbRelease()
21+
22+
name = os["NAME"] ?? "Linux"
23+
version = os["VERSION"] ?? lsb["LSB_VERSION"] ?? ""
24+
id = os["ID"] ?? lsb["DISTRIB_ID"] ?? "linux"
25+
idLike = os["ID_LIKE"]?.split(separator: " ").map { String($0) } ?? []
26+
versionCodename = os["VERSION_CODENAME"] ?? lsb["DISTRIB_CODENAME"] ?? ""
27+
versionId = os["VERSION_ID"] ?? lsb["DISTRIB_RELEASE"] ?? ""
28+
prettyName = os["PRETTY_NAME"] ?? lsb["DISTRIB_DESCRIPTION"] ?? "Linux"
29+
buildId = os["BUILD_ID"] ?? ""
30+
variant = os["VARIANT"] ?? ""
31+
variantId = os["VARIANT_ID"] ?? ""
32+
machineId = LinuxDeviceInfo.getMachineId()
6233
}
63-
34+
6435
private static func getOsRelease() -> [String: String] {
6536
return tryReadKeyValues(path: "/etc/os-release")
6637
}
@@ -82,19 +53,19 @@ class LinuxDeviceInfo : DeviceInfo {
8253
let url = URL(fileURLWithPath: path)
8354
let string = try! String(contentsOf: url, encoding: .utf8)
8455
let lines = string.components(separatedBy: .newlines)
85-
56+
8657
var dict = [String: String]()
8758
for line in lines {
8859
let splits = line.split(separator: "=")
8960
if splits.count > 1 {
9061
let key = String(splits[0])
9162
let value = String(splits[1])
92-
63+
9364
dict[key] = value
9465
}
9566
}
96-
67+
9768
return dict
9869
}
9970
}
100-
#endif
71+
#endif

Sources/Appwrite/DeviceInfo/MacOS/MacOSDeviceInfo.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

Sources/Appwrite/DeviceInfo/OSDeviceInfo.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Foundation
22

3-
protocol DeviceInfo {}
4-
53
class OSDeviceInfo {
64

7-
#if os(iOS) || os(watchOS) || os(tvOS)
8-
var iOSInfo: iOSDeviceInfo?
5+
#if os(iOS) || os(tvOS)
6+
var iOSInfo: IOSDeviceInfo?
7+
#elseif os(watchOS)
8+
var watchOSInfo: WatchOSDeviceInfo?
99
#elseif os(macOS)
1010
var macOSInfo: MacOSDeviceInfo?
1111
#elseif os(Linux)
@@ -15,14 +15,16 @@ class OSDeviceInfo {
1515
#endif
1616

1717
init() {
18-
#if os(iOS) || os(watchOS) || os(tvOS)
19-
self.iOSInfo = iOSDeviceInfo.get()
18+
#if os(iOS) || os(tvOS)
19+
self.iOSInfo = IOSDeviceInfo()
20+
#elseif os(watchOS)
21+
self.watchOSInfo = WatchOSDeviceInfo()
2022
#elseif os(macOS)
21-
self.macOSInfo = MacOSDeviceInfo.get()
23+
self.macOSInfo = MacOSDeviceInfo()
2224
#elseif os(Linux)
23-
self.linuxInfo = LinuxDeviceInfo.get()
25+
self.linuxInfo = LinuxDeviceInfo()
2426
#elseif os(Windows)
25-
self.windowsInfo = LinuxDeviceInfo.get()
27+
self.windowsInfo = LinuxDeviceInfo()
2628
#endif
2729
}
2830
}
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
#if os(Windows)
22
import Foundation
33

4-
class WindowsDeviceInfo : DeviceInfo {
5-
4+
class WindowsDeviceInfo {
5+
66
let numberOfCores: String
77
let computerName: String
88
let systemMemoryInMegabytes: UInt64
9-
10-
public init(
11-
numberOfCores: String,
12-
computerName: String,
13-
systemMemoryInMegabytes: UInt64
14-
) {
15-
self.numberOfCores = numberOfCores
16-
self.computerName = computerName
17-
self.systemMemoryInMegabytes = systemMemoryInMegabytes
18-
}
199

20-
public static func get() -> WindowsDeviceInfo {
21-
let memory = ProcessInfo.processInfo.physicalMemory / 1000 / 1000 // Bytes to MB
22-
23-
return WindowsDeviceInfo(
24-
numberOfCores: ProcessInfo.processInfo.processorCount.description,
25-
computerName: Host.current().localizedName ?? "",
26-
systemMemoryInMegabytes: memory
27-
)
10+
public init() {
11+
numberOfCores = ProcessInfo.processInfo.processorCount.description
12+
computerName = Host.current().localizedName ?? ""
13+
systemMemoryInMegabytes = ProcessInfo.processInfo.physicalMemory / 1000 / 1000 // Bytes to MB
2814
}
2915
}
30-
#endif
31-
16+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#if os(iOS) || os(tvOS)
2+
import Foundation
3+
import UIKit
4+
5+
class IOSDeviceInfo {
6+
7+
let name: String
8+
let systemName: String
9+
let systemVersion: String
10+
let model: String
11+
let localizedModel: String
12+
let identifierForVendor: String
13+
let modelIdentifier: String
14+
15+
public init() {
16+
let device = UIDevice.current
17+
18+
name = device.name
19+
systemName = device.systemName
20+
systemVersion = device.systemVersion
21+
model = device.model
22+
localizedModel = device.localizedModel
23+
identifierForVendor = device.identifierForVendor?.uuidString ?? ""
24+
modelIdentifier = UIDevice.modelName
25+
}
26+
}
27+
#endif

0 commit comments

Comments
 (0)