interface.uts 9.7 KB
Newer Older
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
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<string>;
}

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
};