Open liuboren0617 opened 4 years ago
I have the same problem.
It seems that getLibrary()
returns object like {isLastChunk: true, library: [...]}
.
Modifying the example code to this fixes the error for me:
this.photo.requestAuthorization({read: true}).then( () => {
this.photo.getLibrary().subscribe({
next: (lib: any) => {
lib.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'); }
});
})
Additionally you could create a new interface which matches the object that getLibrary()
returns and cast it to that. The any
cast is just quick and dirty.
The example on the official website has an error
http://www.ionic.wang/native_doc-index-id-231.html