For the complete documentation index, see llms.txt. This page is also available as Markdown.

Device.getPhotos

函数式 API fetchAlbumPhotos也可以通过它使用相同的功能。

功能说明

从用户的相册中获取照片列表。可以设置最大数量和分辨率,可用于图库预览·图片选择等。

如果没有相册读取权限, FetchAlbumPhotosPermissionError会发生。 Device.getPhotos.getPermission()来确认权限状态,并且 Device.getPhotos.openPermissionDialog()可以重新请求权限。

类型

Device.getPhotos(options?: FetchAlbumPhotosOptions): Promise<ImageResponse[]>;

Params

type FetchAlbumPhotosOptions = {
  /** 要获取的照片最大数量。默认值为 10。 */
  maxCount?: number;
  /** 图片的最大宽度(px)。默认值为 1024。 */
  maxWidth?: number;
  /** 是否将图片以 base64 返回。默认值为 false。 */
  base64?: boolean;
};

Response

type ImageResponse = {
  id: string;
  dataUri: string;
};

错误

错误会以类的形式抛出 — error instanceof FetchAlbumPhotosPermissionError来识别。该类可在 @apps-in-toss/web-framework中导入。

错误类
说明

FetchAlbumPhotosPermissionError

表示相册读取权限被拒绝的情况。 Device.getPhotos.openPermissionDialog()可以重新请求。

示例代码

这有帮助吗?