ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.04k stars 999 forks source link

Ask user for LocalNotifications permissions on iOS not working as expected #1797

Closed danielsogl closed 4 years ago

danielsogl commented 5 years ago

Description of the problem: I tried to migrate from Cordova local notifications to the Cpacaitor plugin without success on iOS. When I call the areEnabled() function, the user will not be asked to Garant the permission on iOS. It is not possible to ask before already setting an actual notification. So I changed my Code to something like this:

LocalNotifications.schedule({
        notifications: [],
      })
        .then(res => {
          console.log('init() NOTIFICATIONS ACCEPTED', JSON.stringify(res));
          LocalNotifications.areEnabled().then(res => {
            console.log('areEnabled() then', JSON.stringify(res));
          });
        })
        .catch(err => {
          console.log('init() NOTIFICATIONS REJECTED', JSON.stringify(err));
          LocalNotifications.areEnabled().then(res => {
            console.log('areEnabled() catch', JSON.stringify(res));
          });
          handleRejectedPermission();
        });

The problem is that the promise is resolved before the user clicked any option. I can set the notifications only after a new start of the application by calling the areEnabled() function which now return true.

Maybe I understand the usage of the plugin wrong but it is not that clear like the Cordova Plugin to handle use permissions on iOS.

Affected platform

OS of the development machine

Other information:

Capacitor version: latest

node version: latest

npm version: latest

CocoaPods version: latest

Steps to reproduce:

Link to sample project:

jcesarmobile commented 5 years ago

areEnabled just checks if they are enabled or not at the moment because the users can disable them at any point, but doesn't prompt. What we probably need is a way of requesting the permissions

JhonArlex commented 4 years ago

Hello. I'll work on this problem

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.