Issue
With the playstore requiring the minimumTargetSDK version to be 33, it caused my notification libraries to no longer work with android 13.
Libraries Affected
1. awesome-cordova-plugins/local-notifications/ngx (Local Notification)
2. cordova-plugin-fcm-with-dependecy-updated/ionic/ngx (FCM)
Attemped Solution
Added necessary permission in Android Manifest
<uses-permission android:name="android.permission.NFC" />
Try to request for notification permission to no avail
The former function will return false for requestPermission() without showing the dialog for me to indicate if I want to grant permission to the app.
async askForLocalNotificationPermission() {
if (this.platform.is('android')) {
const hasPermission = await this.localNotifications.requestPermission();
if (hasPermission) {
console.log('Notification permission granted');
} else {
console.log('Notification permission denied');
}
}
}
The latter function will return true for requestPermission() without showing the dialog for me to indicate if I want to grant permission to the app.
async askForFCMNotificationPermission() {
if (this.platform.is('android')) {
const hasPermission = await this.fcm.requestPermission();
if (hasPermission) {
console.log('Notification permission granted');
} else {
console.log('Notification permission denied');
}
}
}
Solution
Upon further debugging,
I have discovered that the permissions libary was outdated and did not include the new permissions necessary for the sending of notification.
Hence the following steps were taking to resolve the issue
- Update cordova-plugin-android-permissions
- Update node_modules/@ionic-native/android-permissions/index.js
- However as there arent any more recent updates for the android-permissions node module which contains the permission setting required to send notifications, I had to manually add the permission into the index.js file.
Add the following code to check and request for permission to send notification
async askForNotificationPermission() { return new Promise((resolve)=> { let phoneVersion = parseInt(this.device.version, 10); if (phoneVersion >= 13) { this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.POST_NOTIFICATIONS).then( result => { if (result.hasPermission) { resolve(true); } else { // Request the permission this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.POST_NOTIFICATIONS).then(permission => { if(permission.hasPermission) { } else{ } resolve(true); }); } }, err => { console.error(err); resolve(true); } ); } });
} }
Answered By - Yeo Bryan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.