Open deepakrout opened 7 years ago
I use the calendar plugin in my ionic2 app too. The following works for me on Android. I haven't tested it on iOS. Note that it resolves a boolean and not data.
Calendar.hasReadWritePermission().then((success) => {
if (!success) {
Calendar.requestReadWritePermission().then((success) => {
if (!success) {
console.log('cannot request Calendar permissions');
} else {
this.calendarOptions = Calendar.getCalendarOptions();
}
});
} else {
this.calendarOptions = Calendar.getCalendarOptions();
}
});
Same issue: iOS does not work. Android works.
iOS: Once the user denied the permission there is no way to request the permission within the app.
Android:
Has anybody a solution for iOS other than telling the user to open the iOS settings?
I can confirm this is still an issue.
I can't even get requestReadWritePermission
to resolve its promise. I've tried manually changing the typscript defs in ionic and passing in a callback too and that doesn't work either.
Nope, I'm having the same issue too, it just doesn't want to resolve...combined with the other issues on the board, it's a problem...
Ok, did some digging the source code and for Android, you can actually request the thing you want to do directly and it should then automagically pop up the permission request alert first if you don't have permissions, meaning you DON'T need to request write permissions.
Sample code as follows:
`// HACK: on iOS, the 'hasWritePermission' call also triggers the Permission request alert, so we can just // call that return new Promise((resolve, reject) => { this.calendar .hasWritePermission() .then(hasPermission => { console.log('CalendarProvider.addEvent() -> hasReadWritePermission: ' + hasPermission);
// HACK: If we're on Android, we try and create the item even if we don't have permission as THIS
// will trigger the dialog
if (hasPermission || this.isOnAndroid) {
return this.createItem(item)
.then(resolve)
.catch(error => {
// HACK: this is the pre-baked messaged that comes out of the plugin that we get on Android
// when permission is turned down, so we intercept and use our own message.
if (error === 'Please allow access to the Calendar and try again.') {
reject(this.Messages.PERMISSION_DENIED);
return;
}
reject(error);
});
}
reject(this.Messages.PERMISSION_DENIED);
})
.catch(reject);
});`
In IOS you need choose Full Access on Info.plist
In our Ionic 2 app in one of the view user can add a particular event to the native Calendar. The issue is when initially it tries to access the ios calendar the user is prompted if they want to allow the app to access the native calendar. Here if the user selects No and later on they try to add an event to the calendar using apps 'Add Event to Calendar' button obviously they can't. However in the app we trying to request read/write permission by first checking Ionic 2 native if Calendar.hasWritePermission() if no then issues Calendar. requestReadWritePermission(). Here nothing happens. Looks like it neither resolves the promise nor rejects the promise. I am expecting in the success of the Calendar.requestReadWritePermission().then() it should bring up the dialog asking the user if they want to allow access to the calendar. Is this a bug or intended behavior? If this is intended then is there way to request permission in the app?
Calendar.requestReadPermission().then(data => { console.log('Request successed! ', data) //This line doesn't get executed }, err => { console.log('Request failed! ', err) //not this line }).catch(err => { console.log('Calendar request access failed.', err) //not even this line })