ionic-team / capacitor

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

LocalNotifications on app start after notification action #1178

Closed dm-AS closed 5 years ago

dm-AS commented 5 years ago

I try to implement LocalNotifications into my app but it won't work if the app has been stopped.

As I see it the event fires before the listener is ready. And after that it seems broken because it doesn't work anymore.

I use beta 17 with Ionic 4.0

app.component.ts

constructor(
        private platform: Platform,
        private router: Router,
        private route: ActivatedRoute,
        private asLocalNotifications: AsLocalNotificationsService,
        private ngZone: NgZone,
    ) {
        LocalNotifications.addListener('localNotificationActionPerformed', (notification) => {
            this.ngZone.run(() => {
                this.router.navigate([notification.notificationRequest.extra.link], {relativeTo: this.route});
            });
        });
        // (<any>window).skipLocalNotificationReady = true;
        this.initializeApp();
    }

    initializeApp() {
        this.platform.ready().then(() => {
            this.asLocalNotifications.checkNotifications();
            // this.localNotifications.fireQueuedEvents();
            SplashScreen.hide();
        });
    }

I had the listener inside initializeApp() before.

How can I get it working or is there a workarround?

solojuve1897 commented 5 years ago

I played around with Push Notifications yesterday to achieve the similar purpose of navigating to a specific page when the notification is pressed and also tried to use the ActionPerformed event for Push Notifications. I didn't succeed and suppose your issue is similar to mine in this regard. Granted, I haven't tested it fully yet and was going to create an issue after the fact.

jcesarmobile commented 5 years ago

Does it happen on Android, iOS or both?

dm-AS commented 5 years ago

For me it's on both. As a workaround for iOS I use cordova-plugin-local-notifications but that doesn't work on android.

jcesarmobile commented 5 years ago

should be fixed in beta 22