On iOS when I call Permission.notification.request() the very first time, and the user clicks "Allow", the return value of PermissionStatus.permanentlyDenied is returned. This should return granted.
When I call Permission.notification.request() the second time the return status of 'granted' is returned.
See code example below:
Future<bool> requestNotificaitonAccess(
{@required BuildContext context}) async {
var status = await Permission.notification.status;
if (status.isGranted) {
print('requestNotificaitonAccess isGranted = true.');
return true;
}
if (status.isDenied) // We have not asked yet
{
var requestedResponse = await Permission.notification.request();
// ERROR: WHEN USER SELECTS 'Allow'
// requestedResponse == PermissionStatus.permanentlyDenied
var secondTryResponbse = await Permission.notification.request();
// secondTryResponbse == PermissionStatus.granted
...
}
Version: 8.1.2
Platform:
For me issue was this:
8.0.0: This release contains the following breaking changes:
Starting from this version the permissions on iOS are disabled by default. To enable a permission, specify the correct GCC_PREPROCESSOR_DEFINITIONS in the ios/Podfile file. For an example check out the Podfile of the example application.
I had to update my pod file to write now only permissions that I want with 1, now everything works for me.
@tkeithblack, it sounds like @tomaschyly solution should fix your problem. Can you tell me if it solved your problem so I can close this issue? Thanks in advance!
Thanks for the suggestion, but I already have the following defined in my podfile
## dart: PermissionGroup.notification
'PERMISSION_NOTIFICATIONS=1',
I dug a little deeper and noticed that for the Notification requests it prompts the user immediately upon checking the status. However, for Contacts and Microphone it does not.
This is what I'm seeing after a fresh app install.
var status = await Permission.microphone.status;
// The above function returns PermissionStatus.denied. However it does NOT
// prompt the user yet. This is consistent with the documentation.
if (status.isDenied || status.isPermanentlyDenied)
{
var requestedResponse = await Permission.microphone.request();
// Upon calling the above request the user is prompted to allow microphone
// This function does not return until the user makes their choice.
// When user selects 'OK' PermissionStatus.granted is returned.
// Again, this is consistent with the expected behavior.
}
However, I am not seeing the expected behavior when calling exactly the same way for notifications.
var status = await Permission.notification.status;
// The above function immediately prompts the user with the permission request
// and immediately returns before user makes a selection. The return value is
// PermissionStatus.permanentlyDenied.
// NOTE: Documentation states this should only check the permissions, not prompt user.
if (status.isDenied || status.isPermanentlyDenied)
{
var requestedResponse = await Permission.notification.request();
// When this function is called it DOES wait, however, the prompt for the user
// to approve notifications has already been displayed with the call to
// await Permission.notification.status
// After user selects 'Allow' requestedResponse == PermissionStatus.permanentlyDenied
// When I make a second call to request, this second call returns PermissionStatus.granted
requestedResponse = await Permission.notification.request();
}
This was tested with version:
permission_handler: ^8.1.4+1
Thanks,
Keith
Most helpful comment
For me issue was this:
8.0.0: This release contains the following breaking changes:
Starting from this version the permissions on iOS are disabled by default. To enable a permission, specify the correct GCC_PREPROCESSOR_DEFINITIONS in the ios/Podfile file. For an example check out the Podfile of the example application.
I had to update my pod file to write now only permissions that I want with 1, now everything works for me.