Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

android M wear case #691

Closed
bitgandtter opened this issue Mar 11, 2016 · 4 comments
Closed

android M wear case #691

bitgandtter opened this issue Mar 11, 2016 · 4 comments

Comments

@bitgandtter
Copy link

I have this service:

angular.module('app.pushNotification', [])
    .factory('pushNotification', function () {
        var push = null;
        var registrationId = null;

        function getRegistrationId() {
            return registrationId;
        }

        function init() {
            if (window.PushNotification) {
                var PushNotification = window.PushNotification;

                push = PushNotification.init({
                    android: {
                        senderID: "xyz",
                        icon: "mum",
                        iconColor: "lightgrey"
                    }
                });

                if (push !== null) {
                    push.on('registration',
                        function (data) {
                            console.log('push registered', data);
                            registrationId = data.registrationId;
                        });

                    push.on('notification', function(data){
                        console.log('push received on init', data);
                    });
                }
            }
        }

        function listenNotification(callback) {
            if (push !== null) {
                push.on('notification', function(data){
                    console.log('push received on listen', data);
                });
            }
        }

        return {
            init: init,
            getRegistrationId: getRegistrationId,
            listenNotification: listenNotification
        };
    });

I call the init function on app start and other services that inject this one call the listenNotification providing a callback to handle the notification data.

NOTE: that the code has been modified to use a dummy function to log the data of the notification on both scenarios on the init function and on the listenNotification function.

For some reason only the function registered on the init receive the notification data, any other registered with the listenNotification function does not receive the notification.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android 6.0
Cordova 6.0
plugin version 1.6

What can be the issue

@macdonst
Copy link
Member

@bitgandtter how do you send the push and what is the payload?

@bitgandtter
Copy link
Author

The push is sent on server side using PHP zendframework/zendservice-google-gcm. The payload is a simple text message.

But besides how its sent and what its in it the recepción should work the same right.

The wear case here is why it only works if the event listeners are place just after initialization. And wont work if i try to register them in some other time after that with the specified funcions

@bitgandtter
Copy link
Author

It was a design flaw, i dont know that the registration event will be emit after init and of course if you register a listener for that event after it was triggered you will never get it.

I advice to add a func to obtain the registrationId so if the event was already triggered you can access the id from that func and wont need to listen to it.

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants