ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web āš”ļø
https://capacitorjs.com
MIT License
11.44k stars 977 forks source link

bug: PushNotifications.register() returns 'undefined' on Android #6553

Closed ashin-kk closed 1 year ago

ashin-kk commented 1 year ago

Bug Report

Capacitor Version

Latest Dependencies:       

  @capacitor/cli: 4.8.0    
  @capacitor/core: 4.8.0   
  @capacitor/android: 4.8.0
  @capacitor/ios: 4.8.0    

Installed Dependencies:    

  @capacitor/cli: 4.7.0
  @capacitor/android: 4.7.0
  @capacitor/core: 4.7.0
  @capacitor/ios: 4.7.0

[success] Android looking great! šŸ‘Œ

Platform(s)

Android

Current Behavior

// PERMISSION CHECKING & REGISTER

 async registerNotifications() {
            let permStatus = await PushNotifications.checkPermissions();

            if (permStatus.receive !== 'granted') {
                permStatus = await PushNotifications.requestPermissions();
            }

            console.log('permStatus :==', permStatus);
            console.log('permStatus receive :==', permStatus.receive);

            const register = await PushNotifications.register();
            console.log('register :==', register);
        },

// RESULT IN LOG image

Expected Behavior

Code Reproduction

Other Technical Details

I followed as mentioned on the official plugin page. Added google-services.json file as well. Don't know what's missing. Please guide. I am just a beginner in capacitor.

npm --version output: 9.6.1

node --version output: v18.15.0

pod --version output (iOS issues only): NA

Additional Context

jcesarmobile commented 1 year ago

yeah, that's what register method returns https://capacitorjs.com/docs/apis/push-notifications#register

for getting the push token you have to add a listener for registration https://capacitorjs.com/docs/apis/push-notifications#addlistenerregistration

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.