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

iOS addUnreadMessagesListener callback fired after message center opens #13

Open
jfspencer opened this issue Dec 1, 2015 · 3 comments

Comments

@jfspencer
Copy link

Apptentive.addUnreadMessagesListener's success callback only gets fired after the user enters the message center.

Here is my setup code

init(userContact) {
    var apptentiveRegistration = {
        initialize: () => {
            document.addEventListener('deviceready', apptentiveRegistration.onDeviceReady, false);
            Apptentive.setPersonEmail(
                ()=> {this.jnLog.breadcrumb('apptentive user email registered'); },
                ()=> {this.jnLog.breadcrumb('apptentive user email registration failed'); },
                userContact.email);
            Apptentive.setPersonName(
                ()=> {this.jnLog.breadcrumb('apptentive user name registered'); },
                ()=> {this.jnLog.breadcrumb('apptentive user name registration failed'); },
                userContact._displayName());
        },
        onDeviceReady: () => {
            document.addEventListener('resume', apptentiveRegistration.onResume, false);
            document.addEventListener('pause', apptentiveRegistration.onPause, false);
            Apptentive.deviceReady(
                ()=> {this.jnLog.breadcrumb('apptentive device ready registered'); },
                ()=> {this.jnLog.breadcrumb('apptentive device ready registration failed'); });
            Apptentive.addUnreadMessagesListener(
                (messageCount) => {
                    this.jnLog.breadcrumb('did enter apptentive message listener call back', messageCount);
                    this.$rootScope.$broadcast(con.jn.eventApp.apptentiveMsgCount, messageCount);
                },
                (error) => { this.jnLog.error('apptentive message count update error', error); }
            );
        },
        onResume: () => {
            Apptentive.resume(
                ()=> {this.jnLog.breadcrumb('apptentive resume registered'); },
                ()=> {this.jnLog.breadcrumb('apptentive resume registration failed'); });
        },
        onPause: () => {
            Apptentive.pause(
                ()=> {this.jnLog.breadcrumb('apptentive pause registered'); },
                ()=> {this.jnLog.breadcrumb('apptentive pause registration failed'); });
        }
    };
    apptentiveRegistration.initialize();

(written in typescript)

@pmwisdom
Copy link

👍

@pmwisdom
Copy link

A way around this is to poll the plugin with this command :

setInterval(function() {
    Apptentive.getUnreadMessageCount(function(numMessages) { console.log(numMessages) })
}, 1000);

@sebaferreras
Copy link

sebaferreras commented Feb 1, 2018

The issue happens also on Android. I was able to reproduce this issue when using:

Cordova Platform: 7.0.1 – 7.1.0+
Cordova Android Platform: 6.3.0+

@skykelsey is this a bug or should we use a setInterval in order to listen to changes in the unread messages count?

Thanks 😃

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

No branches or pull requests

3 participants