JiGuang Push
is an independent third-party cloud push platform in China, which can quickly integrate the message push function of Android and iOS platforms. There may not be many users in other countries. If you need English instructions, you can submit an issue.
vapor
是一个swift
语言开发的服务器框架,该项目是在vapor
框架下集成使用极光推送的库。
使用swift
语言开发,基于极光推送
官网的Rest Api
接口,三行代码即可快速集成服务器端功能。
可以采用SPM方式添加,也可以采用源文件方式添加
在Vapor
项目的Package
文件中,在dependencies
添加依赖
.package(url: "https://github.com/DamonHu/HDJGPushTool-Vapor.git", from: "1.0.0"),
在targets
中添加
.target(name: "App", dependencies: ["Vapor", "HDJGPushTool"]),
在Vapor
项目的Package
文件中,在dependencies
添加依赖
.package(url: "https://github.com/DamonHu/HDJGPushTool-Vapor.git", from: "4.0.0"),
在targets
中添加
.target(name: "App", dependencies: [
.product(name: "HDJGPushTool", package: "HDJGPushTool-Vapor"),
]),
将本git仓库里面的Sources
目录下的HDJGPushTool
整个文件夹拖入添加到工程即可
//1、导入通知类
import HDJGPushTool
//2、创建通知对象, 记得把JiguangAppkey和JiguangSecret替换为你自己应用的appkey和secret
let pushTool = HDJGPushTool(appKey: JiguangAppkey, appSecrect: JiguangSecret)
//3、创建通知内容
let pushModel = HDJGPushModel(alertTitle: "通知的标题", alertContent: "通知的内容")
//4、发送通知
try pushTool.pushNotification(req, pushModel: pushModel)
示例:
router.post("notice/callback", String.parameter) { (req) -> String in
let webName = try req.parameters.next(String.self)
//发送通知
let pushTool = HDJGPushTool(appKey: Lazypig_jiguangAppkey, appSecrect: Lazypig_jiguangSecret)
let pushModel = HDJGPushModel(alertTitle: "网站回调了", alertContent: "有网站请求回调")
try pushTool.pushNotification(req, pushModel: pushModel)
return "回调成功"
}
可以通过设置pushModel
实现更多操作,推送的目标,可以参考极光的文档设置: 极光推送官方文档
let pushModel = HDJGPushModel(alertTitle: "通知的标题", alertContent: "通知的内容")
//推送到测试环境
pushModel.apnsProduction = fasle
//单独推送的平台
pushModel.platform = .ios
//推送的目标,可通过registrationId、tag、tagAnd、tagNot、alias等创建audience设置专门的推送目标,如果设置为null则为推送给全部用户
pushModel.audience = HDJGPushAudienceModel(registrationId: AdminPushList)
直接使用极光的api会更灵活,你可以进行参考或者扩充以便更加方便使用