未在插件“ PhotoLibrary” ionic 4中定义方法“ requestAuthorization:”

时间:2019-04-17 09:27:06

标签: ios cordova ionic-framework plugins ionic4

我已经添加了照片库插件,请按照离子文档here上的说明进行操作

我使用ionic cordova plugin add cordova-plugin-photo-library --variable PHOTO_LIBRARY_USAGE_DESCRIPTION="To choose photos" --save命令添加插件

使用ionic cordova platform add ios命令添加平台后

当我从照片库中获取所有照片时,我得到以下错误提示

  

错误:插件未定义方法'requestAuthorization:'   “照相馆”

我在按钮点击时定义该方法,如下所示

async getAllPhotos() {
    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 => { console.log('could not get photos'); },
            complete: () => { console.log('done getting photos'); }
        });
    }).catch(err => console.log('permissions weren\'t granted'));
}

我在这里添加ionic info

离子:

   ionic (Ionic CLI)             : 4.10.2 (/Users/atologistimac2/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.1.2
   @angular-devkit/build-angular : 0.13.7
   @angular-devkit/schematics    : 7.2.4
   @angular/cli                  : 7.3.7
   @ionic/angular-toolkit        : 1.4.1

科尔多瓦:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.4, ios 5.0.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.0.1, (and 18 other plugins)

系统:

   ios-deploy : 1.9.4
   ios-sim    : 7.0.0
   NodeJS     : v10.15.1 (/usr/local/bin/node)
   npm        : 6.9.0
   OS         : macOS High Sierra
   Xcode      : Xcode 10.1 Build version 10B61

我在这里做什么错了?

如果有解决方案,请与他人分享,将不胜感激

谢谢

1 个答案:

答案 0 :(得分:0)

这是我解决的方法...最好安装以下具有正确版本的插件,它将完美运行。

cordova插件rm cordova-plugin-add-swift-support cordova插件rm cordova-plugin-photo-library

cordova插件添加cordova-plugin-add-swift-support@1.7.2 cordova插件添加https://github.com/nilebma/cordova-plugin-photo-library.git

,一切都会恢复正常。如果您遇到任何问题,只需手动从plugins文件夹中删除这些插件,然后安装插件即可。