1
- import { PushNotifications } from ' @capacitor/push-notifications' ;
1
+ import { PushNotifications } from " @capacitor/push-notifications" ;
2
2
3
3
const register = async ( ) => {
4
+ let STATUS = await PushNotifications . checkPermissions ( ) ;
5
+ console . log ( STATUS ) ;
4
6
5
- let STATUS = await PushNotifications . checkPermissions ( ) ;
6
- console . log ( STATUS ) ;
7
+ if ( STATUS . receive === "prompt" ) {
8
+ STATUS = await PushNotifications . requestPermissions ( ) ;
9
+ console . log ( STATUS ) ;
10
+ }
7
11
8
- if ( STATUS . receive === 'prompt' ) {
9
- STATUS = await PushNotifications . requestPermissions ( ) ;
10
- console . log ( STATUS ) ;
11
- }
12
+ if ( STATUS . receive !== "granted" ) {
13
+ console . log ( "not permission" ) ;
14
+ }
12
15
13
- if ( STATUS . receive !== 'granted' ) {
14
- console . log ( 'not permission' ) ;
15
- }
16
+ await PushNotifications . register ( ) ;
16
17
17
- await PushNotifications . register ( ) ;
18
-
19
- PushNotifications . addListener ( 'registration' , ( token ) => {
20
- console . log ( token ) ;
21
- } ) ;
18
+ PushNotifications . addListener ( "registration" , ( token ) => {
19
+ console . log ( token ) ;
20
+ } ) ;
22
21
23
- PushNotifications . addListener ( ' registrationError' , ( error ) => {
24
- console . log ( error ) ;
25
- } ) ;
22
+ PushNotifications . addListener ( " registrationError" , ( error ) => {
23
+ console . log ( error ) ;
24
+ } ) ;
26
25
27
- PushNotifications . addListener ( ' pushNotificationReceived' , ( notification ) => {
28
- console . log ( notification ) ;
29
- } ) ;
26
+ PushNotifications . addListener ( " pushNotificationReceived" , ( notification ) => {
27
+ console . log ( notification ) ;
28
+ } ) ;
30
29
31
- PushNotifications . addListener ( ' pushNotificationActionPerformed' , ( action ) => {
32
- console . log ( action ) ;
33
- } ) ;
30
+ PushNotifications . addListener ( " pushNotificationActionPerformed" , ( action ) => {
31
+ console . log ( action ) ;
32
+ } ) ;
34
33
} ;
35
34
36
- register ( ) ;
35
+ register ( ) ;
0 commit comments