javascript - 如何在 react native expo 中访问相机应用程序中拍摄的照片?
问题描述
我用 expo 相机模块制作了一个相机应用程序,我现在正试图访问这个应用程序中的特定相册,就像它发生在移动原生相机应用程序中一样。我尝试按照我看到的一些模糊说明创建一个类似的函数,但我不知道这是正确的路径。
//trying to access photos taken through the square
const albumName = "Gryffindor";
async function seePhotos() {
const getTakenPhotos = await MediaLibrary.getAssetsAsync({
first: 20,
album: albumName,
sortBy: ["creationTime"],
});
console.log(getTakenPhotos.assets);
return MediaLibrary.getAssetsAsync.asset.uri;
}
<View style={{ flex: 1, alignItems: "center" }}>
<Icon name="square" size={50} color="white" onPress={seePhotos} />
</View>;
解决方案
用这个替换上面的代码
const albumName = "Gryffindor";
const seePhotos = async () => {
try {
const getTakenPhotos = await MediaLibrary.getAssetsAsync({
first: 20,
album: albumName,
sortBy: MediaLibrary.SortBy.creationTime, // Should be written like this
});
console.log(getTakenPhotos.assets); // Check Your console
} catch (error) {
console.log(error); // In case of any error
}
};
推荐阅读
- mysql - 为什么在 Mysql EXPLAIN 中 EXTRA 为 NULL?为什么 >= 是使用索引条件?
- c++ - 可选的
> 与可选 & - 实际例子? - sql - 如何将 CONNECT BY PRIOR Oracle 样式查询重写为 RECURSIVE CTE Postgres 以进行具有相关 WHERE 子句的查询?
- vb.net - ++ 在 VB.NET 中做了什么(如果有的话)?
- c# - Razor 页面:值不会从 OnGet() 停留在 OnPost()
- ibm-cloud - IBM Graph 还存在吗?
- c# - 是否可以在不使用证书的情况下进行数字签名和验证签名?
- reactjs - React-redux,无法与我的根组件使用连接
- loops - 埃菲尔横跨 an_iterable as vs is
- javascript - 如何编辑 PubNub 消息并添加对单个消息的反应