export interface Uni { /** * getPushClientId() * @description * 获取客户端唯一的推送标识 * @param {GetPushClientIdOptions} * @return {void} * @tutorial http://uniapp.dcloud.io/api/plugins/push.html#getpushclientid * @uniPlatform { * "app": { * "android": { * "osVer": "4.4", * "uniVer": "√", * "unixVer": "3.97" * }, * "ios": { * "osVer": "9.0", * "uniVer": "x", * "unixVer": "x" * } * } * } * @example ```typescript uni.getPushClientId({ complete: (res: any) => { console.log("getPushClientId complete => " + JSON.stringify(res)); } }); ``` */ getPushClientId(options : GetPushClientIdOptions) : void; /** * onPushMessage() * @description * 启动监听推送消息事件 * @param {OnPushMessageCallback} * @return {void} * @tutorial http://uniapp.dcloud.io/api/plugins/push.html#onpushmessage * @uniPlatform { * "app": { * "android": { * "osVer": "4.4", * "uniVer": "√", * "unixVer": "3.97" * }, * "ios": { * "osVer": "9.0", * "uniVer": "x", * "unixVer": "x" * } * } * } * @example ```typescript uni.onPushMessage((res : OnPushMessageCallbackResult) => { console.log("onPushMessage => " + JSON.stringify(res)) }); ``` */ onPushMessage(callback : OnPushMessageCallback) : void; /** * offPushMessage() * @description * 关闭推送消息监听事件 * @param {OnPushMessageCallback} * @return {void} * @tutorial http://uniapp.dcloud.io/api/plugins/push.html#offpushmessage * @uniPlatform { * "app": { * "android": { * "osVer": "4.4", * "uniVer": "√", * "unixVer": "3.97" * }, * "ios": { * "osVer": "9.0", * "uniVer": "x", * "unixVer": "x" * } * } * } * @example ```typescript const cb = (res : OnPushMessageCallbackResult) => { console.log("onPushMessage => " + JSON.stringify(res)) } uni.offPushMessage(cb); ``` */ offPushMessage(callback : OnPushMessageCallback) : void; /** * getChannelManager() * @description * 获取通知渠道管理器,Android 8系统以上才可以设置通知渠道,Android 8系统以下返回null。 * @param {void} * @return {ChannelManager} * @uniPlatform { * "app": { * "android": { * "osVer": "4.4", * "uniVer": "3.97", * "unixVer": "3.97" * }, * "ios": { * "osVer": "9.0", * "uniVer": "x", * "unixVer": "x" * } * } * } * @example ```typescript const channelManager = uni.getChannelManager(); channelManager.setPushChannel({ channelId: "test1", channelDesc: "test1 desc", soundName: "pushsound" }) const channels = channelManager.getAllChannels() as string[] console.log("channels : " + channels); ``` */ getChannelManager() : ChannelManager; /** * createPushMessage() * @description * 创建本地通知栏消息 * @param {CreatePushMessageOptions} * @return {void} * @tutorial http://uniapp.dcloud.io/api/plugins/push.html#createpushmessage * @uniPlatform { * "app": { * "android": { * "osVer": "4.4", * "uniVer": "√", * "unixVer": "3.97" * }, * "ios": { * "osVer": "9.0", * "uniVer": "x", * "unixVer": "x" * } * } * } * @example ```typescript uni.createPushMessage({ title:"hello", content: "content" }); ``` */ createPushMessage(options : CreatePushMessageOptions) : void; } export type GetPushClientId = (options : GetPushClientIdOptions) => void; export type GetPushClientIdSuccess = { /** * 个推客户端推送id,对应uni-id-device表的push_clientid */ cid : string, /** * 错误描述 */ errMsg : string }; export type GetPushClientIdSuccessCallback = (result : GetPushClientIdSuccess) => void; export type GetPushClientIdFail = UniError; export type GetPushClientIdFailCallback = (result : GetPushClientIdFail) => void; export type GetPushClientIdComplete = any; export type GetPushClientIdCompleteCallback = (result : GetPushClientIdComplete) => void; export type GetPushClientIdOptions = { /** * 接口调用成功的回调函数 * @defaultValue null */ success : GetPushClientIdSuccessCallback | null, /** * 接口调用失败的回调函数 * @defaultValue null */ fail : GetPushClientIdFailCallback | null, /** * 接口调用结束的回调函数(调用成功、失败都会执行) * @defaultValue null */ complete : GetPushClientIdCompleteCallback | null }; /** * 事件类型 * - click 从系统推送服务点击消息启动应用事件 * - receive 应用从推送服务器接收到推送消息事件 */ export type OnPushMessageType = "click" | "receive"; export type OnPushMessageCallbackResult = { /** * 事件类型 * @type{OnPushMessageType} */ type : OnPushMessageType, /** * 消息内容 */ data : UTSJSONObject }; export type OnPushMessageCallback = (result : OnPushMessageCallbackResult) => void; export type OnPushMessage = (callback : OnPushMessageCallback) => void; export type OffPushMessage = (callback : OnPushMessageCallback) => void; export type GetChannelManager = () => ChannelManager; export type SetPushChannelOptions = { /** * 添加的声音文件,注意raw目录下必须要有 ,不传此字段将使用默认铃音。 * @defaultValue null */ soundName? : string | null, /** * 通知渠道id */ channelId : string, /** * 通知渠道描述 */ channelDesc : string, /** * 呼吸灯闪烁 * @defaultValue false */ enableLights? : boolean | null, /** * 震动 * @defaultValue false */ enableVibration? : boolean | null, /** * 通知的重要性级别,可选范围IMPORTANCE_LOW:2、IMPORTANCE_DEFAULT:3、IMPORTANCE_HIGH:4 。 * @defaultValue 3 */ importance? : number | null, /** * 锁屏可见性,可选范围VISIBILITY_PRIVATE:0、VISIBILITY_PUBLIC:1、VISIBILITY_SECRET:-1、VISIBILITY_NO_OVERRIDE:-1000。 * @defaultValue -1000 */ lockscreenVisibility? : number | null } export interface ChannelManager { /** * 设置推送渠道 * * @uniPlatform { * "app": { * "android": { * "osVer": "4.4", * "uniVer": "√", * "unixVer": "3.97" * }, * "ios": { * "osVer": "9.0", * "uniVer": "x", * "unixVer": "x" * } * } * } */ setPushChannel(options : SetPushChannelOptions) : void; /** * 获取当前应用注册的所有的通知渠道。 * * @uniPlatform { * "app": { * "android": { * "osVer": "4.4", * "uniVer": "√", * "unixVer": "3.97" * }, * "ios": { * "osVer": "9.0", * "uniVer": "x", * "unixVer": "x" * } * } * } */ getAllChannels() : Array; } export type CreatePushMessage = (options : CreatePushMessageOptions) => void; export type CreatePushMessageSuccess = {}; export type CreatePushMessageSuccessCallback = (result : CreatePushMessageSuccess) => void; export type CreatePushMessageFail = UniError; export type CreatePushMessageFailCallback = (result : CreatePushMessageFail) => void; export type CreatePushMessageComplete = any; export type CreatePushMessageCompleteCallback = (result : CreatePushMessageComplete) => void; export type CreatePushMessageOptions = { /** * 是否覆盖上一次提示的消息 * @type boolean * @defaultValue false */ cover? : boolean | null, /** * 提示消息延迟显示的时间,单位为s * @defaultValue 0 */ delay? : number | null, /** * 推送消息的图标 * @defaultValue null */ icon? : string | null, /** * 推送消息的提示音 * - system: 使用系统通知提示音(默认值) * - none: 不使用提示音 * @type 'system' | 'none' * @defaultValue "system" */ sound? : string | null, /** * 推送消息的标题 * @defaultValue "" */ title? : string | null, /** * 消息显示的内容,在系统通知中心中显示的文本内容 */ content : string, /** * 消息承载的数据,可根据业务逻辑自定义数据格式 * @defaultValue null */ payload? : any | null, /** * 消息上显示的提示时间 * @defaultValue 当前时间 */ when? : number | null, /** * 渠道id * @defaultValue "DcloudChannelID" * @uniPlatform { * "app": { * "android": { * "osVer": "4.4", * "uniVer": "√", * "unixVer": "3.97" * }, * "ios": { * "osVer": "9.0", * "uniVer": "x", * "unixVer": "x" * } * } * } */ channelId? : string | null, /** * 通知类别 * @defaultValue null * @uniPlatform { * "app": { * "android": { * "osVer": "4.4", * "uniVer": "√", * "unixVer": "3.97" * }, * "ios": { * "osVer": "9.0", * "uniVer": "x", * "unixVer": "x" * } * } * } */ category? : string | null, /** * 接口调用成功的回调函数 * @defaultValue null */ success : CreatePushMessageSuccessCallback | null, /** * 接口调用失败的回调函数 * @defaultValue null */ fail : CreatePushMessageFailCallback | null, /** * 接口调用结束的回调函数(调用成功、失败都会执行) * @defaultValue null */ complete : CreatePushMessageCompleteCallback | null };