测试已测试 | ✓ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新版本 | 2017年9月 |
SwiftSwift版本 | 4.0 |
SPM支持SPM | ✓ |
由 Daniel Egerev 维护。
Swift 的 IoT-Ticket REST 客户端
要将 IoTTicketSwiftAPI 作为 Swift 包管理器 包使用,只需在您的 Package.swift 文件中添加以下内容。
import PackageDescription
let package = Package(
name: "IoTTicketSwiftAPI",
dependencies: [
.Package(url: "https://github.com/iDanbo/IoTTicketSwiftAPI.git", "0.0.3")
]
)
如果您不想使用上述任何依赖管理器,您可以手动将 IoTTicketSwiftAPI 集成到您的项目中。
cd
命令执行到您的顶级项目目录中,运行以下命令(前提是您的项目没有初始化为 git 版本库)$ git init
$ git submodule add https://github.com/iDanbo/IoTTicketSwiftAPI.git
$ git submodule update --init --recursive
打开新的 IoTTicketSwiftAPI
文件夹,并将 IoTTicketSwiftAPI.xcodeproj
拖入您应用程序的 Xcode 项目的 Project Navigator 中。
它应出现在您的应用程序蓝色项目图标下面。它是在所有其他 Xcode 组的上面还是下面并不重要。
在 Project Navigator 中选择 IoTTicketSwiftAPI.xcodeproj
,并验证部署目标与您的应用程序目标匹配。
接下来,在 Project Navigator 中选择您的应用程序项目(蓝色项目图标),导航到目标配置窗口,在侧边栏的 "Targets" 标题下选择应用程序目标。
在此窗口顶部的标签栏中,打开 "General" 面板。
在 "Embedded Binaries" 部分下方单击 +
按钮。
您将看到两个不同的 IoTTicketSwiftAPI.xcodeproj
文件夹,每个文件夹内都有一个嵌套在 "Products" 文件夹中的 IoTTicketSwiftAPI.framework
的两个不同版本。
您可以选择哪个 "Products" 文件夹并不重要。
选择 IoTTicketSwiftAPI.framework
。
就这么简单!
IoTTicketSwiftAPI.framework
被自动添加为目标依赖项,链接框架和嵌入框架,并在复制文件构建阶段链接,这是您在模拟器和设备上构建所需的所有内容。
+
按钮。IoTTicketSwiftAPI.framework
。import IoTTicketSwiftAPI
let username = "username"
let password = "password"
let baseURL = "https://my.iot-ticket.com/api/v1/"
let client = IoTTicketClient(baseURL: baseURL, username: username, password: password)
let device = Device(name: "My iPhone", manufacturer: "Apple", type: "iPhone", deviceDescription: "Device registered with iOS framework", attributes: [deviceAttribute(key: "swift", value: "api"), deviceAttribute(key: "create", value: "apps")])
client.registerDevice(device: device) { deviceDetails, error in
if let error = error {
switch error {
// Handle error
}
}
if let deviceDetails = deviceDetails {
// Save your device details
}
}
let latitude = Datanode(name: "Latitude", path: "Location", v: 63.0951)
let longitude = Datanode(name: "Longitude", path: "Location", v: 21.6165)
client.writeDatanode(deviceId: deviceId, datanodes: [latitude, longitude])
client.getDatanodes(deviceId: deviceId, limit: 10, offset: 0) { deviceDatanodes, error in
if let deviceDatanodes = deviceDatanodes {
// List datanodes
}
}
let fromDate = dateToTimestamp(date: "2016-02-21 00:00:00")
let toDate = dateToTimestamp(date: "2017-04-11 00:00:00")
client.readDatanodes(deviceId: deviceId, criteria: ["latitude", "longitude"], fromDate: fromDate, toDate: toDate, limit: 10000) { datanodeRead, error in
if let datanodes = datanodeRead?.datanodes {
// Read datanodes with values
}
}
client.getDevices { devicesList, error in
if let deviceList = deviceList {
// List your devices
}
}
client.getDevice(deviceId: deviceId) { deviceDetails, error in
if let deviceDetails = deviceDetails {
// Information for a specific device
}
}
client.getAllQuota { quota, error in
if let quota = quota {
// Your overall quota
}
}
client.getDeviceQuota(deviceId: deviceId) { deviceQuota, error in
if let deviceQuota = deviceQuota {
// Device specific quota
}
}
有关更多信息,请参阅 IoT-Ticket REST API 文档
https://www.iot-ticket.com/images/Files/IoT-Ticket.com_IoT_API.pdf.
IoTTicketSwiftAPI 在 MIT 许可下发布。有关详细信息,请参阅 LICENSE。