该服务允许轻松地将 Gorush 集成到 Vapor 中,以发送推送通知。
.package(url: "https://github.com/TICESoftware/vapor-gorush.git", from: "1.0.0")
// ...
.target(name: "App", dependencies: ["Vapor", "Gorush"])
从 1.0.0 版本开始,本包使用 Vapor 4。 如果您想在 Vapor 3 中使用 Gorush,可以使用 0.9.0 版本。
let hostname = Environment.get("GORUSH_HOSTNAME")
app.gorush.use { req in
Gorush(client: req.client, hostname: hostname)
}
默认情况下,将使用 HTTPS。 要使用 HTTP 代替,只需将 httpScheme: .http
添加到初始化中。
import Gorush
// ...
let notification = GorushNotification(tokens: ["deviceToken"], platform: .ios, message: "Push message", title: "Push title")
req.gorush.dispatch(notification, on: req.eventLoop).map { (response: GorushResponse) in
if !response.logs.isEmpty {
// This means an error occurred, if Gorush was configured to return errors
}
}
// ...
此 vapor-gorush 包在 MIT 许可下发布。 有关更多信息,请参见 License。