Hi sorry for newbie question. I want to use this plugin on my ionic 2 project. I tried to convert sample code to angular 2. Since I’m using .then() as a substitute for callback I always got error “Cannot read property ‘then’ of undefined”. I want to know if it is possible to change callback to .then() promises. If possible I want to know why I already tried this code:
let permissions = cordova.plugins.permissions;
permissions.hasPermission(permissions.READ_EXTERNAL_STORAGE)
.then((status:any) => console.log(‘status.hasPermission’));
The plugin of cordova for android permission didn’t implement the Promises. If you want to use .then() function you must read this http://learnangular2.com/es6/promises.
addPermission(androidPermission: any) {
return new Promise((resolve, reject) => {
let permissions = cordova.plugins.permissions;
permissions.requestPermission(androidPermission, function(status) {
if (status.hasPermission){
resolve("Permission is now granted");
} else{
reject('Permission is not turned on');
}
}, reject('Permission is not turned on'));
});