katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.75k forks source link

The notification don't work if I'm coding it in other view different to the index.html #1670

Closed ginirocha45 closed 5 days ago

ginirocha45 commented 6 years ago

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

Provide a general summary of the issue.

Your Environment

Expected Behavior

The notification arrives without having the view open (I mean, when it was coding) or the app open

Actual Behavior

The notification don't arrives if the view isn't open (I mean, when it was coding) or the app isn't open

Steps to Reproduce

Good afternoon

Nice to meet you, my name is Gina, and I am learning how to make mobile applications (I´m beginner coding). I chose the plugin that you did for notifications (https://github.com/katzer/cordova-plugin-local-notifications) to use it in my app, but it only works if I have open the view where I coded the notification.

I would like to know how I can do so that the notification appears without being in the view where it was coded, I mean, that the notification arrives without having the view open or the app open.

Thank you

Context

I thought that if i changed the variable index in the javascript local-notification (plugins/cordova-plugin-local-notification code line 930) it would work how I need, but it didn't work.

Debug logs

Include iOS / Android logs

Tawpie commented 6 years ago

@ginirocha45 it would help us help you if you post the code you're using to schedule the notification. Also, when you say the notification doesn't arrive, do you mean that it doesn't appear in the phone's notification shade and action bar? Or do you mean it does appear in the notification shade and action bar but when you click on it the app doesn't open and show the notification inside your app?

ginirocha45 commented 6 years ago

This is the code that I'm coding in the index:

        var ultFecha = "8/20/2018";
        var sigFecha = moment(ultFecha).add(7,'day').add(15,'h').add(59,'m').format('llll');

        document.addEventListener("deviceready", ondeviceready, false);
        function ondeviceready(){
            cordova.plugins.notification.local.schedule({
                title: 'Design team meeting',
                text: '3:00 - 4:00 PM',
                trigger: { at: new Date(sigFecha) }
            });

If I paste that code in other view (for example prueba.html), it doesn't arrive and it doesn't appear in the phone's notification shade and action bar

rwillett commented 6 years ago

1524 has full production working code on setting a notification a few minutes in the future. Try that code.

ginirocha45 commented 6 years ago

Thank you @rwillett, I'm going to read the issue!

ginirocha45 commented 6 years ago

Is it necessary that this code cordova.plugins.notification.local.schedule( [ { id: 1 , sound: "" , // Turn the sound off trigger: { at: reminder0 } , data: { type: "CongestionChargeNotification" , original_schedule_time: original_schedule_time0 , reminder_type: "reminder0_congestion_charge" , order: 1} , smallIcon: "res://pw_notification.png" , text: "You've crossed into the Congestion Zone and might need to pay. You'll get more reminders later today." } , { id: 2 , sound: "" , // Turn the sound off trigger: { at: reminder1 } , data: { type: "CongestionChargeNotification" , original_schedule_time: original_schedule_time1 , reminder_type: "reminder1_congestion_charge" , order: 2} , smallIcon: "res://pw_notification.png" , text: "Reminder 1 - Don't forget to pay the Congestion Charge before midnight." }] to be inside the next code? document.addEventListener("deviceready", ondeviceready, false); function ondeviceready(){ /---/ ); }

Because without the previous code in the console appear this: Uncaught TypeError: Cannot read property 'notification' of undefined at prueba.html:91, being prueba.html:91 cordova.plugins.notification.local.schedule.

rwillett commented 6 years ago

Then you have a different issue.

That code comes from a production app running 0.9.0-beta.3 on IOS 10, 11 and Android 5,6,7 and 8. Its in the codebases specifically for testing local notifications and for demos.

Without code it's impossible to say anything else. The fact you have:

Uncaught TypeError: Cannot read property 'notification' of undefined

makes me think you've made a mistake. Sadly my ability to analyse code mistakes without code is limited.

Why are you running Beta 2.

ginirocha45 commented 6 years ago

I'm sorry! I hadn't view the file of the plugin. The version is 0.9.0-beta.3

This is the code that I'm used:

index.html:

It have a tag a with href=prueba.html

prueba.html:

`

`

rwillett commented 6 years ago

This appears to be a coding issue in the way you have built your Cordova app. Notifications work well across multiple controllers.

I would suspect you have not set up your Cordova project correctly and are doing everything in the index.html file. You need to setup Controllers and Services to really get the power out of Cordova.

Our index.html file is quite small, but we have dozens of other TypeScript files to support that one index.html file.