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

bug: Local Notification - Unable to cancel notifications via LocalNotificationDescriptor: ios #4658

Closed stillerest closed 3 years ago

stillerest commented 3 years ago

Bug Report

Capacitor Version

Latest Dependencies:

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

Installed Dependencies:

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

[success] iOS looking great! [success] Android looking great!

Platform(s)

Current Behavior

The notification can be created on iOS, but it is not possible to cancel it correctly. After creating the notification and executing the "schedule" method, the notification pops up. When the "cancel" method is called, the method is executed and resolved, but the notification is not closed and is still displayed.

On Android, the same code is executed successfully and the notification gets closed correctly.

Expected Behavior

When creating and scheduling a notification with id "x" (e.g. 1), it should be possible to cancel this notification with the method cancel(). This should be called with a LocalNotificationDescriptor array in which an object with the correct id "x" is defined.

This behaviour should not only be possible on Android but also on IOS.

Code Reproduction

Create notification with e.g. ID 1

let notification: LocalNotificationSchema;
notification = {
    id: 1,
    title: "Title",
    body: "Body"
};

if (this.isAndroid()) {
    notification.largeIcon = "res://icon";
    notification.smallIcon = "res://icon";
    notification.sound = "sound.mp3";
    notification.autoCancel = true;
} else if (this.isIos()) {
    notification.sound = "file://assets/sound/sound.mp3";
} 

await LocalNotifications.schedule({
    notifications: [notification]
});

Cancel notification with the same ID 1

const clearNotifications: Array<LocalNotificationDescriptor> = [];
clearNotifications.push({
    id: 1
});

LocalNotifications.cancel({
    notifications: clearNotifications
}).then((res) => {
    console.debug("resolved");
}).catch((error) => {
    console.debug(error);
});

Other Technical Details

npm --version output: 6.14.8

node --version output: v12.13.0

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

The Code was tested using WebStorm (Version: 2021.1) and XCode (Version: 12.3) with multiple emulators (e.g. iPhone 12 Pro Max - 14.3) OS: macOS Catalina - Version: 10.15.7 Plugin: "@capacitor/local-notifications": "~1.0.0"

Additional Context

See code example. The same code was used for Android and IOS, but only Android cancels notifications correctly.

Ionitron commented 3 years ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron 💙

Ionitron commented 3 years ago

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day! Ionitron 💙

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.