适用于 apialerts.com 平台的 Swift 客户端
文档 • GitHub • Swift Package Index
将以下依赖项添加到您的 Package.swift 文件中
let package = Package(
...
dependencies: [
.package(url: "https://github.com/apialerts/apialerts-swift.git", exact: "<latest-version>")
],
targets: [
.target(
...
dependencies: [
.product(name: "APIAlerts", package: "apialerts-swift"),
]
)
]
或者通过您的 Xcode 项目安装它
https://github.com/apialerts/apialerts-swift.git
目前,apialerts-swift 仅作为 SPM 包提供。
import APIAlerts
...
// Set the default api key to use in all send() calls at any time in your app
APIAlerts.configure(
apiKey: "your-api-key"
)
配置客户端是可选的,但它允许您为所有 send() 调用设置默认 API 密钥。如果您不配置客户端,则必须在 send() 调用中设置 API 密钥。
快速一行代码即可将通知发送到您连接的设备。
APIAlerts.send(
apiKey: "your-api-key", // Optional, uses the key from ApiAlerts.client.configure() if not provided
channel: "your-channel", // Optional, uses the default channel if not provided
message: "New App User!" // Required
)
可以使用可选参数设置其他事件属性。
APIAlerts.send(
apiKey: "your-api-key", // Optional, uses the key from ApiAlerts.client.configure() if not provided
channel: "your-channel", // Optional, uses the default channel if not provided
message: "New App User!", // Required
tags: ["tag1", "tag2"], // Optional tags
link: "https://apialerts.com" // Optional link
)
send() 函数中提供的 API 密钥可以与 configure() 函数中设置的默认 API 密钥不同。 这允许您将事件发送到不同的工作区,而无需更改默认 API 密钥或管理客户端的多个实例。
如果您需要等待成功执行,还可以使用 APIAlerts.sendAsync 方法。 但是,通常总是首选 send() 函数。
如果您有任何问题或反馈,请在我们的 GitHub 存储库上创建一个 issue。 我们一直在努力改进我们的服务,并希望收到您的来信。 感谢您使用 API Alerts!