requestPermission
函数式 API
requestPermission也可以这样使用同样的功能。
功能说明
请求权限。如果是尚未确定的(notDetermined)权限,则向用户展示权限请求;如果是已确定的权限,则原样返回已确定的状态。结果始终为 allowed 或 denied。
类型
requestPermission(permission: { name: PermissionName; access: PermissionAccess }): Promise<Exclude<PermissionStatus, "notDetermined">>;Params
type PermissionName =
"clipboard" | "contacts" | "photos" | "geolocation" | "camera" | "microphone";
type PermissionAccess = "read" | "write" | "access";Response
type PermissionStatus = "notDetermined" | "denied" | "allowed";
// 请求结果为不包含 notDetermined 的 "allowed" | "denied" 之一。示例代码
import { Permissions } from "@apps-in-toss/web-framework";
const status = await requestPermission({ name: "camera", access: "access" });
if (status === "allowed") {
console.log("摄像头权限已被允许。");
}这有帮助吗?