是否有可能使用离子图像库应用程序

时间:2017-05-19 12:19:51

标签: android ios cordova mobile ionic-framework

我需要在android&&和ios。当用户打开应用程序时,用户应该看到手机中的图像并选择它们。我不想使用使用Intents的图像选择器。是否可以在cordova phonegap或者类似离子的混合框架上构建这个程序,或者我应该使用原生android ios?

1 个答案:

答案 0 :(得分:0)

实际上我们可以像这样从设备上获取照片;使用离子https://ionicframework.com/docs/native/photo-library/

中的PhotoLibrary
`this.photoLibrary.requestAuthorization().then(() => {
  this.photoLibrary.getLibrary().subscribe({
    next: library => {
      library.forEach(function(libraryItem) {
        console.log(libraryItem.id);          // ID of the photo
        console.log(libraryItem.photoURL);    // Cross-platform access to photo
        console.log(libraryItem.thumbnailURL);// Cross-platform access to thumbnail
        console.log(libraryItem.fileName);
        console.log(libraryItem.width);
        console.log(libraryItem.height);
        console.log(libraryItem.creationDate);
        console.log(libraryItem.latitude);
        console.log(libraryItem.longitude);
        console.log(libraryItem.albumIds);    // array of ids of appropriate AlbumItem, only of includeAlbumsData was used
      });
    },
    error: err => {},
    complete: () => { console.log('could not get photos'); }
  });
})
.catch(err => console.log('permissions weren't granted'));`

别忘了像这样在app.module导入库

import { PhotoLibrary } from '@ionic-native/photo-library';
相关问题