Uniapp SDK #
import { UPush, UPushListener } from '@/uni_modules/upush2-uni-client/js_sdk/upush2-uni-client.js'
UPush #
/**
* 配置
* @param {String} packageName 包名/BundleId/小程序ID,android,ios生产环境(打包)从系统读取包名参数无效
* @param {String} appId 项目唯一标示
* @param {String} appKey 应用唯一标示
* @param {UPushListener} listener 时间监听
*/
configUPush(packageName, appId, appKey, listener)
/**
* 注册推送
* @param {String} wsUrl websocket地址
* @returns
*/
registerUPush(wsUrl)
/**
* 注册到指定连接服务
* @param {String} wsUrl websocket地址
*/
registerSpecifiedUPushServer(wsUrl)
/**
* 注销
*/
unregisterUPush()
/**
* 绑定用户
* @param {String} userId 用户唯一标示
*/
bindUser(userId)
/**
* 取得绑定的userId
*/
getUserId()
/**
* 取得状态
*/
getStatus()
/**
* 获得PushToken
*/
getPushToken()
UPushListener #
/**
* pushToken监听
* @event {Function(code: Int, pushToken: String, userId: String)} cb
*/
setOnPushToken(cb)
/**
* 接收消息
* @event {Function(msg: UMessage, timestamp: Date, isOfflineMsg: Boolean)} cb 支持async
*/
setOnPush(cb)
/**
* 注销完成监听
* @event {Function()} cb
*/
setOnUnregister(cb)
/**
* 消息撤回
* @event {Function(msg: UMessage, timestamp: Date)} cb
*/
setOnRevoke(cb)
/**
* 状态监听
* @event {Function(status: Int)} cb
*/
setOnStatus(cb)
/**
* 绑定用户监听
* @event {Function(status: Int)} cb
*/
setOnBindUser(cb)
/**
* 用户在其他设备注册,被顶掉
* @event {Function({ip, platform}} cb
*/
setOnRegisteredOnAnotherDevice(cb)
/**
* 通知栏点击事件,app端可用
* @event {Function(msg: UMessage)} cb
*/
setOnNotificationClicked(cb)
/**
* 通知栏显示前回调,app端可用
* @event {Function(notification: Object, msg: UMessage, revoke: Bool): Bool} cb
* @example notification ios {title, body, subTitle, largeIcon, category}
* @example notification android {title, body, largeIcon, channelId}
*/
setOnLocalNotificationWillAppear(cb)