跳到主要内容
版本:v2

Photos

相册 API 提供了从用户照片库中加载照片和相册的方法,并支持保存照片。

API

getPhotos(...)

getPhotos(options?: PhotosFetchOptions) => Promise<PhotosResult>

从用户的照片库中获取照片

参数类型
options
PhotosFetchOptions

返回值:

Promise<PhotosResult>


getAlbums(...)

getAlbums(options?: PhotosAlbumsFetchOptions) => Promise<PhotosAlbumsResult>

从用户的照片库中获取相册

参数类型
options
PhotosAlbumsFetchOptions

返回值:

Promise<PhotosAlbumsResult>


savePhoto(...)

savePhoto(options?: PhotosSaveOptions) => Promise<PhotosSaveResult>

将照片保存到用户的照片库

参数类型
options
PhotosSaveOptions

返回值:

Promise<PhotosSaveResult>


createAlbum(...)

createAlbum(options: PhotosCreateAlbumOptions) => Promise<void>

在用户的照片库中创建相册

参数类型
options
PhotosCreateAlbumOptions

Interfaces

PhotosResult

属性类型描述
photosPhotoAsset[]从照片库返回的照片列表

PhotoAsset

属性类型描述
identifierstring平台特定的标识符
datastring照片资源的 base64 编码数据(仅支持 JPEG 格式)
creationDatestring资源创建日期的 ISO 日期字符串
fullWidthnumber原始资源的完整宽度
fullHeightnumber原始资源的完整高度
thumbnailWidthnumber缩略图预览的宽度
thumbnailHeightnumber缩略图预览的高度
location
PhotoLocation
资源的位置元数据

PhotoLocation

属性类型描述
latitudenumber拍摄照片时的 GPS 纬度
longitudenumber拍摄照片时的 GPS 经度
headingnumber拍摄照片时用户的朝向
altitudenumber拍摄照片时用户的海拔高度
speednumber拍摄照片时用户的速度

PhotosFetchOptions

属性类型描述
quantitynumber要获取的照片数量,按最后创建日期降序排列
thumbnailWidthnumber返回缩略图的宽度
thumbnailHeightnumber返回缩略图的高度
thumbnailQualitynumber返回缩略图的 JPEG 质量(0-100)
typesstring要返回的资源类型(当前仅支持 "photos")
albumIdentifierstring查询的相册标识符(可通过 getAlbums() 获取标识符)

PhotosAlbumsResult

属性类型描述
albumsPhotosAlbum[]从查询返回的相册列表

PhotosAlbum

属性类型描述
identifierstring相册的本地标识符
namestring相册名称
countnumber相册中的项目数量
type
PhotosAlbumType
相册类型

PhotosAlbumsFetchOptions

属性类型描述
loadSharedboolean是否加载云共享相册

PhotosSaveResult

属性类型描述
successboolean照片是否创建成功

PhotosSaveOptions

属性类型描述
datastring照片的 base64 编码 JPEG 数据(注意:不要添加 HTML data-uri 类型前缀)
albumIdentifierstring可选的要保存照片的相册标识符

PhotosCreateAlbumOptions

属性类型
namestring

Enums

PhotosAlbumType

成员描述
Smart"smart"智能相册(如"收藏夹"或"最近添加")
Shared"shared"云共享相册
User"user"用户创建的相册