@ capgo/ 电容器- photo- 图书馆
在您的 Capacitor app 中构建自己的相册画廊:列表相册,通过照片和带缩略图的视频页面,或者打开本地取相机,没有完整的图书库访问权限.
🤖 建筑与AI编码代理? 安装 Capgo 技能 所以克劳德代码,代码,光标,副驾驶,或双子座CLI知道如何安装和使用
@capgo/capacitor-photo-library在您的电容应用程序中:npx skills add Cap-go/capgo-skills。然后问你的经纪人: 将@capgo/capor-photo-library添加到我的Capacitor应用上,并把它接上 代理设置指南 • 妇女 主机磁共振
主要特点
- 图书馆访问数字 :
checkAuthorization()财务报告和审定财务报表requestAuthorization(),包括iOS的有限访问. - 专辑和资产数字 :
getAlbums()财务报告和审定财务报表getLibrary()与呼和可选视频. - 显示 URL数字 :
getThumbnailUrl()财务报告和审定财务报表getPhotoUrl()返回您的 WebView 可显示的 URL. - 系统拾取器数字 :
pickMedia()带有选择限制,不需要库权限. - 平台: iOS和Android. 互联网档案馆的存檔,存档日期2013-12-21. iOS使用相片和相片UI,Android使用MediaStore. 在网上不可用.
文档
这里有最完整的医生: https://capgo.app/docs/plugins/相-图书馆/
兼容性
| 插件版本 | 电容兼容性 | 维护 |
|---|---|---|
| 联合国 | 联合国 | ✅ |
| 页:1 | 页:1 | 应要求 |
| 页:1 | 页:1 | ❌ |
| 页:1 | 页:1 | ❌ |
说明: 此插件的主要版本沿用了Capacitor的主要版本. 使用匹配您的 Capacitor 安装的版本( 如 Capacitor 8 的插件 v8) 。 只有最新的主要版本得到积极维护.
安装
您可以使用我们的 AI 辅助设置安装插件 。 使用以下命令将 Capgo 技能添加到您的 AI 工具 :
npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins
然后使用下列提示:
Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-photo-library` plugin in my project.
如果您更喜欢手动设置,请通过运行以下命令来安装插件,并遵循下面的平台特定指令:
npm install @capgo/capacitor-photo-library
npx cap sync
使用量
import { Capacitor } from '@capacitor/core';
import { PhotoLibrary } from '@capgo/capacitor-photo-library';
const { state } = await PhotoLibrary.requestAuthorization();
if (state === 'authorized' || state === 'limited') {
const { assets, hasMore } = await PhotoLibrary.getLibrary({
limit: 100,
thumbnailWidth: 256,
thumbnailHeight: 256,
});
const gallery = assets.map(asset => ({
id: asset.id,
fileName: asset.fileName,
thumbnailUrl: asset.thumbnail
? asset.thumbnail.webPath ?? Capacitor.convertFileSrc(asset.thumbnail.path)
: undefined,
photoUrl: asset.file
? asset.file.webPath ?? Capacitor.convertFileSrc(asset.file.path)
: undefined,
}));
console.log('Loaded', gallery.length, 'items. More available?', hasMore);
}
const picked = await PhotoLibrary.pickMedia({
selectionLimit: 3,
includeVideos: true,
});
console.log('User selected', picked.assets.length, 'items');
程序缓存中的本地执行缓存导出文件
目录。 您可以安全删除 photoLibrary 缓存下的文件夹,如果
你需要腾出空间.
API 密码
checkAuthorization()requestAuthorization()getAlbums()getLibrary(...)getPhotoUrl(...)getThumbnailUrl(...)pickMedia(...)getPluginVersion()- 接口
- 类型异名
检查认证( C)
checkAuthorization() => Promise<{ state: PhotoLibraryAuthorizationState; }>
在不提示用户的情况下返回当前授权状态 .
回返情况: Promise<{ state: PhotoLibraryAuthorizationState; }>
请求认证 ()
requestAuthorization() => Promise<{ state: PhotoLibraryAuthorizationState; }>
必要时请求访问相片库.
回返情况: Promise<{ state: PhotoLibraryAuthorizationState; }>
获取 Albums ()
getAlbums() => Promise<{ albums: PhotoLibraryAlbum[]; }>
获取可用的相册 .
回返情况: Promise<{ albums: PhotoLibraryAlbum[]; }>
获取图书馆(...)
getLibrary(options?: GetLibraryOptions | undefined) => Promise<GetLibraryResult>
检索库资产以及可以在网页视图中显示的URL.
| 参数 | 类型 |
|---|---|
options | GetLibraryOptions |
回返情况: Promise<GetLibraryResult>
获取 PhotoUrl (...)
getPhotoUrl(options: { id: string; }) => Promise<PhotoLibraryFile>
获取资产全解析版本的可显示 URL .
如果你已经打电话 getLibrary 与 includeFullResolutionData,你平时
不需要这种方法.
| 参数 | 类型 |
|---|---|
options | { id: string; } |
回返情况: Promise<PhotoLibraryFile>
获取 ThumbnailUrl (...)
getThumbnailUrl(options: { id: string; width?: number; height?: number; quality?: number; }) => Promise<PhotoLibraryFile>
获取资产缩略图的可显示 URL .
| 参数 | 类型 |
|---|---|
options | { id: string; width?: number; height?: number; quality?: number; } |
回返情况: Promise<PhotoLibraryFile>
选择媒体(...)
pickMedia(options?: PickMediaOptions | undefined) => Promise<PickMediaResult>
打开本地系统取取器,使用户可以选择媒体而无需提供完整的相片库访问权限. 所选文件被复制到应用程序缓存中,并以可移植的URL返回.
| 参数 | 类型 |
|---|---|
options | PickMediaOptions |
回返情况: Promise<PickMediaResult>
获取 PluginVersion ()
getPluginVersion() => Promise<{ version: string; }>
获取本地 Capacitor 插件版本
回返情况: Promise<{ version: string; }>
接口
图片库
| Prop | 类型 |
|---|---|
id | string |
title | string |
assetCount | number |
获取图书馆档案
| Prop | 类型 | 说明 |
|---|---|---|
assets | PhotoLibraryAsset[] | |
totalCount | number | 库中匹配查询的资产总数 . assets.length 当使用页化时,可以小于此值. |
hasMore | boolean | 使用 pagination 时是否有更多资产可用 . |
相片图书馆
| Prop | 类型 | 说明 |
|---|---|---|
id | string | |
fileName | string | |
type | PhotoAssetType | |
width | number | |
height | number | |
duration | number | |
creationDate | string | |
modificationDate | string | |
latitude | number | |
longitude | number | |
mimeType | string | |
size | number | 如果有的话,操作系统报告的基本资产的字节大小. |
albumIds | string[] | |
thumbnail | PhotoLibraryFile | |
file | PhotoLibraryFile |
相片图书馆文件
| Prop | 类型 | 说明 |
|---|---|---|
path | string | 本地文件系统中的绝对路径 . |
webPath | string | 可在网页视图内使用的 URL 。 通常由 Capacitor.convertFileSrc(path)。 。 。 . |
mimeType | string | |
size | number | 已知的字节大小, 否则 -1。 。 。 . |
获取图书馆选项
| Prop | 类型 | 说明 |
|---|---|---|
offset | number | 从查询开始跳过的资产数量 . |
limit | number | 最多资产数量。 放弃所有匹配的东西. |
includeImages | boolean | 在结果中包含图像 。 默认为 true。 。 。 . |
includeVideos | boolean | 在结果中包含视频. 默认为 false。 。 。 . |
includeAlbumData | boolean | 包含每个资产所属相册的信息 。 默认为 false。 。 。 . |
includeCloudData | boolean | 包括存储于云(iCloud / Google Photos)的资产. 默认为 true。 。 。 . |
useOriginalFileNames | boolean | 若为 true,在可用时使用操作系统报告的原始文件名. |
thumbnailWidth | number | 生成缩略图的宽度 。 默认为 512。 。 。 . |
thumbnailHeight | number | 生成缩略图的高度 。 默认为 384。 。 。 . |
thumbnailQuality | number | JPEG 生成缩略图的质量 (0-1). 默认为 0.5。 。 。 . |
includeFullResolutionData | boolean | 何时 true,将完整的大小资产复制到应用程序缓存并返回其URL。 默认为 false。 。 。 . |
选择媒体
| Prop | 类型 |
|---|---|
assets | PhotoLibraryAsset[] |
选择媒体选项
| Prop | 类型 | 说明 |
|---|---|---|
selectionLimit | number | 用户可以选择的最大项目数 。 使用 0 允许无限选择。 默认为 1。 。 。 . |
includeImages | boolean | 允许用户选择图像 。 默认为 true。 。 。 . |
includeVideos | boolean | 允许用户选择视频. 默认为 false。 。 。 . |
thumbnailWidth | number | 选中项目生成的缩略图的宽度 。 默认为 256。 。 。 . |
thumbnailHeight | number | 所选项目生成缩略图的高度 。 默认为 256。 。 。 . |
thumbnailQuality | number | JPEG 生成缩略图的质量 (0-1). 默认为 0.7。 。 。 . |
类型异名
照片图书馆认证状态
'authorized' | 'limited' | 'denied' | 'notDetermined'
相片设定类型
'image' | 'video'