Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification works only if the app is active #1283

Closed
RcBuilder opened this issue May 1, 2017 · 5 comments
Closed

Notification works only if the app is active #1283

RcBuilder opened this issue May 1, 2017 · 5 comments

Comments

@RcBuilder
Copy link

RcBuilder commented May 1, 2017

Issue : Notification works only if the app is active

plugin link: https://github.com/katzer/cordova-plugin-local-notifications

I'm using an hybrid app cordova with jquery mobile and signalR.
When the app is active (in the foreground) it works perfectly but once i move to other app or hide the apps all together it doesn't work.
I also added a jquery mobile popup to confirm that the issue is not signalR related and the pop up was shown

platforms:

  1. jquery mobile 1.4.5
  2. cordova cli 6.1.1
  3. plugin (latest)

What I did to solve :

Error : nothing happens when app is on the background, all working perfectly when app is on the foreground

Example code :

function onDeviceReady() {
cordova.plugins.notification.local.registerPermission(function (granted) {
console.log('Permission has been granted: ' + granted);
});
};

function onNotificationReceived(notification) {
// show popup
var body = notification.senderInfo + " " + notification.body;
$('#popup-notification').first('p').html(body).end().popup('open');

// show device alert with beeping
navigator.notification.alert(notification.body, null, notification.senderInfo);
navigator.notification.beep(1);

// add notification to the device notifications bar
cordova.plugins.notification.local.schedule({
    text: notification.body,
    title: notification.senderInfo
});

}

Thanks.
Roby.

@rwillett
Copy link
Collaborator

rwillett commented May 1, 2017

Fill out #1188 as not enough information here.

You've not mentioned phones, what you are trying to do, what works, what the code looks like.

@RcBuilder
Copy link
Author

updated

@rwillett
Copy link
Collaborator

rwillett commented May 3, 2017

You still haven't actually provided enough information, e.g. IOS, Android, version of mobile OS, what you expect to happen. Any errors.

The reason for the template is to avoid all this back and forth asking for more info as people don't provide enough information. Saying plugin is the latest is meaningless as people often use what they think is the latest plugin, and it turns out to be an old one.

You have no date as to when you schedule the plugin. When do you expect it to fire? There are simple examples in the docs. Have you followed them?

@RcBuilder
Copy link
Author

hey , more info about my environment:
i tested it with some different phones - all of them use Android os.
one of them is Note 3 with android 5.
i'm not getting any error.
i'm expecting to get notified via the notifications bar.

using plugin version 0.8.4:

i wan't it to fire immediately with no schedule.
note that IT IS WORKING once the app is open in the foreground
but doesn't fire when it in the background

thanks, Roby (-:

@RcBuilder
Copy link
Author

hey, i found it!
your code is working perfectly, it was my mistake
i saved a state of the device ready in a local storage and i added a return clause when its not ready in order to support the web browser (it's an hybrid app so i can reach it via any explorer on the desktop - which is great for debugging cause i can create multiple instances)
once the device was in the background - its state changed into 'not ready' so it never reached the code snippet! (lol)

sorry 'bout the inconvenience and many many thanks for your help and service

great weekend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants