IBM Worklight push notification not showing after authentication

0

Hi I have a very strange Push Notification issue. I tried with the provided PushNotification project and everything worked fine for me. But now in my app when I tried to implement it in a similar manner I got this issue. So what I have done is in my main.js file I have added the following code for the user to be able to subscribe.

if (WL.Client.Push){

    WL.Client.Push.onReadyToSubscribe = function(){
        alert("onReadyToSubscribe");

            alert("You said yes");
            WL.Client.Push.registerEventSourceCallback(
                    "myPush1", 
                    "PushAdapter", 
                    "PushEventSource1", 
                    pushNotificationReceived);
            if(!WL.Client.Push.isSubscribed("myPush1"))
                {
                    if(confirm('Do you allow CSOL to send notification to you?')) {
                        WL.Client.Push.subscribe("myPush1", {
                            onSuccess: doSubscribeSuccess,
                            onFailure: doSubscribeFailure
                        });
                }
                }
            else
                {
                alert(WL.Client.Push.isSubscribed("myPush1"));
                }





    };

}

PushAdapter-impl.js

 /*
    *  Licensed Materials - Property of IBM
    *  5725-G92 (C) Copyright IBM Corp. 2006, 2013. All Rights Reserved.
    *  US Government Users Restricted Rights - Use, duplication or
    *  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
    */

    WL.Server.createEventSource({
        name: 'PushEventSource1',
        onDeviceSubscribe: 'deviceSubscribeFunc',
        onDeviceUnsubscribe: 'deviceUnsubscribeFunc',
        securityTest:'PushApplication-strong-mobile-securityTest'
    });

    function deviceSubscribeFunc(userSubscription, deviceSubscription){
        WL.Logger.debug(">> deviceSubscribeFunc");
        WL.Logger.debug(userSubscription);
        WL.Logger.debug(deviceSubscription);
    }

    function deviceUnsubscribeFunc(userSubscription, deviceSubscription){
        WL.Logger.debug(">> deviceUnsubscribeFunc");
        WL.Logger.debug(userSubscription);
        WL.Logger.debug(deviceSubscription);
    }

    function javaCheck(requestID, oldStatus, newStatus){
         return {
                result : com.ibm.mycsol.pushdemo.push(requestID, oldStatus, newStatus)
            };
    }

    function submitNotification(userId, notificationText){
        //userId = WL.Server.getActiveUser()
        var userSubscription = WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource1', userId);

        if (userSubscription==null){
            return { result: "No subscription found for user :: " + userId };
        }

        var badgeDigit = 1;

        var notification = WL.Server.createDefaultNotification(notificationText, 1, {userId:userId});

        WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText);

        //WL.Server.notifyAllDevices(userSubscription, notification);
        WL.Server.notifyAllDevices(userSubscription, notification);

        return { 
            result: "Notification sent to user :: " + userId 
        };
    }

Everything works fine when I have the app in the foreground. Or when I have pressed the home button on my phone I receive the notification and clicking on the notification reopens the app and shows the specific notification. But when I press the backbutton or I logout I receive the notification, clicking on the notification takes me back to the app and asks me for login. But once I login I am not able to see the notification. I am using a custom login module which checks the username password against a hardcoded string value. Here is the log

02-27 11:50:21.981: V/WebViewInputDispatcher(30541): blockWebkitDraw
02-27 11:50:21.981: V/WebViewInputDispatcher(30541): blockWebkitDraw lockedfalse
02-27 11:50:22.286: D/webview(30541): blockWebkitViewMessage= false
02-27 11:50:22.336: D/myCSOLApp(30541): Request [login]
02-27 11:50:22.351: D/ProgressBar(30541): setProgress = 0
02-27 11:50:22.351: D/ProgressBar(30541): setProgress = 0, fromUser = false
02-27 11:50:22.351: D/ProgressBar(30541): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 10000
02-27 11:50:22.381: D/dalvikvm(30541): GC_FOR_ALLOC freed 277K, 20% free 10773K/13392K, paused 11ms, total 11ms
02-27 11:50:22.411: D/dalvikvm(30541): GC_FOR_ALLOC freed 376K, 19% free 10877K/13392K, paused 10ms, total 10ms
02-27 11:50:22.426: D/WebView(30541): onSizeChanged - w:320 h:547
02-27 11:50:22.481: D/ProgressBar(30541): updateDrawableBounds: left = 0
02-27 11:50:22.481: D/ProgressBar(30541): updateDrawableBounds: top = 0
02-27 11:50:22.481: D/ProgressBar(30541): updateDrawableBounds: right = 48
02-27 11:50:22.481: D/ProgressBar(30541): updateDrawableBounds: bottom = 48
02-27 11:50:22.556: D/myCSOLApp(30541): Request [http://9.127.62.227:10080/MYCSOL/apps/services/api/myCSOLApp/android/query]
02-27 11:50:22.621: D/myCSOLApp(30541): Request [http://9.127.62.227:10080/MYCSOL/apps/services/api/myCSOLApp/android/query]
02-27 11:50:22.756: D/ProgressBar(30541): setProgress = 0
02-27 11:50:22.756: D/ProgressBar(30541): setProgress = 0, fromUser = false
02-27 11:50:22.756: D/ProgressBar(30541): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 10000
02-27 11:50:22.761: D/myCSOLApp(30541): Request [http://9.127.62.227:10080/MYCSOL/apps/services/api/myCSOLApp/android/query]
02-27 11:50:22.806: D/ProgressBar(30541): updateDrawableBounds: left = 0
02-27 11:50:22.806: D/ProgressBar(30541): updateDrawableBounds: top = 0
02-27 11:50:22.806: D/ProgressBar(30541): updateDrawableBounds: right = 48
02-27 11:50:22.806: D/ProgressBar(30541): updateDrawableBounds: bottom = 48
02-27 11:50:22.846: E/ViewRootImpl(30541): sendUserActionEvent() mView == null
02-27 11:50:30.956: D/myCSOLApp(30541): Clearing notification subscriptions.
02-27 11:50:30.956: D/myCSOLApp(30541): Updating notification subscriptions.
02-27 11:50:30.961: D/WLDroidGap(30541): unregisterReceivers:Receiver not registered: null
02-27 11:50:30.961: D/WLDroidGap(30541): unregisterReceivers:Receiver not registered: null
02-27 11:50:30.966: D/WLDroidGap(30541): Activity started from message notification
02-27 11:50:30.966: D/WLDroidGap(30541): Queuing message for dispatch to javascript
02-27 11:50:30.966: D/WLDroidGap(30541): dispatchPending called. Number of pending messages: 1
02-27 11:50:30.966: W/ResourceType(30541): No package identifier when getting name for resource number 0x00000064
02-27 11:50:30.966: D/WLDroidGap(30541): dispatchPending webView=com.worklight.androidgap.WLWebView{4285e1d8 VFEDH.CL .F....I. 0,0-320,547 #64} messageCallback=null
02-27 11:50:30.966: D/WLDroidGap(30541): dispatchPending called. Number of pending messages: 1
02-27 11:50:30.966: W/ResourceType(30541): No package identifier when getting name for resource number 0x00000064
02-27 11:50:30.966: D/WLDroidGap(30541): dispatchPending webView=com.worklight.androidgap.WLWebView{4285e1d8 VFEDH.CL .F....I. 0,0-320,547 #64} messageCallback=null
02-27 11:50:30.966: V/GCMRegistrar(30541): Registering receiver
02-27 11:50:30.966: D/GCMRegistrar(30541): resetting backoff for com.myCSOLApp
02-27 11:50:30.971: V/GCMRegistrar(30541): Registering app com.myCSOLApp of senders 774173770625
02-27 11:50:30.986: D/myCSOLApp(30541): response [http://9.127.62.227:10080/MYCSOL/apps/services/api/myCSOLApp/android/query] success: /*-secure-
02-27 11:50:30.986: D/myCSOLApp(30541): {"totalTime":8024,"isSuccessful":true,"requests":[{"isFav":"N","comments":[{"SEQNO":"1122","USERNAME":"EDGAR2 CAMARENA2テスト","COMMENTTYPE":"BP","REQUESTCOMMENT_ID":"20879","REQUESTID":"GASUK1402261122","COMMENTTEXT":"sdfdsf","UPDTIMESTAMP":"2014-02-26 13:52:59.684675","ANSWER":"","UPDUSERID":"ecamaren@mx1.ibm.com"}],"REQTYPE":"Create new maintenance proposal","REQUESTID":"GASUK1402261122","TYPE":"TSSP","WWW_STATUS":"Submitted","UPDTIMESTAMP":""},{"isFav":"N","comments":[{"SEQNO":"1121","USERNAME":"EDGAR2 CAMARENA2テスト","COMMENTTYPE":"BP","REQUESTCOMMENT_ID":"20878","REQUESTID":"GASUK1402261121","COMMENTTEXT":"sdfsdf","UPDTIMESTAMP":"2014-02-26 13:08:41.661944","ANSWER":"","UPDUSERID":"ecamaren@mx1.ibm.com"}],"REQTYPE":"Create new maintenance proposal","REQUESTID":"GASUK1402261121","TYPE":"TSSP","WWW_STATUS":"Submitted","UPDTIMESTAMP":""}],"stat":"ok","responseHeaders":{"Server":"WebSphere Application Server\/8.5","X-Powered-By":"Servlet\/3.0","Transfer-Encoding":"chunked","Content-Language":"en-US","Content-Type":"application\/json","Date":"Thu, 27 Feb 2014 03:50:32 GMT"},"WL-Authentication-Success":{"wl_deviceNoProvisioningRealm":{"userId":"0afa2eb3-708a-3b1e-a2cf-79f4afe26820","attributes":{"mobileClientData":"com.worklight.core.auth.ext.MobileClientData@2db9f248"},"isUserAuthenticated":1,"displayName":"0afa2eb3-708a-3b1e-a2cf-79f4afe26820"},"wl_antiXSRFRealm":{"userId":"hq7l1qekklblb3lfa2no754oc6","attributes":{},"isUserAuthenticated":1,"displayName":"hq7l1qekklblb3lfa2no754oc6"},"wl_remoteDisableRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null"},"CustomAuthenticatorRealm":{"userId":"ecamaren@mx1.ibm.com","attributes":{"AuthenticationDate":"Thu Feb 27 11:50:24 SGT 2014","userIdentity":null},"isUserAuthenticated":1,"displayName":null}},"statusReason":"OK","notificationSubscriptionState":{"token":"APA91bGYP18rdbg_25Ginyts3qGmCPDMqLV4AEQARVEFSARyKyGexuKFIhuloZbg0tWzzq_35fURNdKTNNJYsWFnBv3Yk7VndDVIXKENS9kJb7byAuolhZpISM_lH9FEZuyXb8dv3zokJLuynDQm9URZ5EY9x1UeuA","eventSources":[{"alias":"myPush1","eventSource":"PushEventSource1","adapter":"PushAdapter"}]},"responseID":"11","responseTime":8024,"statusCode":200}*/
02-27 11:50:31.031: E/ViewRootImpl(30541): sendUserActionEvent() mView == null
02-27 11:50:31.066: E/myCSOLApp(30541): [http://9.127.62.227:10080/MYCSOL/apps/services/api/myCSOLApp/android/query] exception. TypeError: Cannot read property 'user' of null
02-27 11:50:31.081: D/CordovaLog(30541): Uncaught TypeError: Cannot read property 'user' of null
02-27 11:50:31.081: E/Web Console(30541): Uncaught TypeError: Cannot read property 'user' of null:1714
02-27 11:50:31.216: D/myCSOLApp(30541): response [http://9.127.62.227:10080/MYCSOL/apps/services/api/myCSOLApp/android/query] success: /*-secure-
02-27 11:50:31.216: D/myCSOLApp(30541): {"totalTime":8508,"isSuccessful":true,"requests":[{"isFav":"N","comments":[{"SEQNO":"1124","USERNAME":"EDGAR2 CAMARENA2テスト","COMMENTTYPE":"BP","REQUESTCOMMENT_ID":"20881","REQUESTID":"GASUK1402261124","COMMENTTEXT":"sdfsdf","UPDTIMESTAMP":"2014-02-26 14:47:40.002743","ANSWER":"","UPDUSERID":"ecamaren@mx1.ibm.com"}],"REQTYPE":"Accept maintenance contract","REQUESTID":"GASUK1402261124","TYPE":"TSSC","WWW_STATUS":"Submitted","UPDTIMESTAMP":""},{"isFav":"N","comments":[{"SEQNO":"1123","USERNAME":"EDGAR2 CAMARENA2テスト","COMMENTTYPE":"BP","REQUESTCOMMENT_ID":"20880","REQUESTID":"GASUK1402261123","COMMENTTEXT":"dfgdf","UPDTIMESTAMP":"2014-02-26 14:34:24.679642","ANSWER":"","UPDUSERID":"ecamaren@mx1.ibm.com"}],"REQTYPE":"Accept maintenance contract","REQUESTID":"GASUK1402261123","TYPE":"TSSC","WWW_STATUS":"Submitted","UPDTIMESTAMP":""}],"stat":"ok","responseHeaders":{"Server":"WebSphere Application Server\/8.5","X-Powered-By":"Servlet\/3.0","Transfer-Encoding":"chunked","Content-Language":"en-US","Content-Type":"application\/json","Date":"Thu, 27 Feb 2014 03:50:33 GMT"},"statusReason":"OK","responseID":"12","responseTime":8508,"statusCode":200}*/
02-27 11:50:31.271: E/myCSOLApp(30541): [http://9.127.62.227:10080/MYCSOL/apps/services/api/myCSOLApp/android/query] exception. TypeError: Cannot read property 'user' of null
02-27 11:50:31.286: D/CordovaLog(30541): Uncaught TypeError: Cannot read property 'user' of null
02-27 11:50:31.286: E/Web Console(30541): Uncaught TypeError: Cannot read property 'user' of null:1714
02-27 11:50:31.436: V/GCMBroadcastReceiver(30541): onReceive: com.google.android.c2dm.intent.REGISTRATION
02-27 11:50:31.436: V/GCMBroadcastReceiver(30541): GCM IntentService class: com.myCSOLApp.GCMIntentService
02-27 11:50:31.436: V/GCMBaseIntentService(30541): Acquiring wakelock
02-27 11:50:31.441: V/GCMBaseIntentService(30541): Intent service name: GCMIntentService-774173770625-2
02-27 11:50:31.446: D/GCMBaseIntentService(30541): handleRegistration: registrationId = APA91bGYP18rdbg_25Ginyts3qGmCPDMqLV4AEQARVEFSARyKyGexuKFIhuloZbg0tWzzq_35fURNdKTNNJYsWFnBv3Yk7VndDVIXKENS9kJb7byAuolhZpISM_lH9FEZuyXb8dv3zokJLuynDQm9URZ5EY9x1UeuA, error = null, unregistered = null
02-27 11:50:31.446: D/GCMRegistrar(30541): resetting backoff for com.myCSOLApp
02-27 11:50:31.446: V/GCMRegistrar(30541): Saving regId on app version 1
02-27 11:50:31.446: D/WLDroidGap(30541): Registered at the GCM server with registration id APA91bGYP18rdbg_25Ginyts3qGmCPDMqLV4AEQARVEFSARyKyGexuKFIhuloZbg0tWzzq_35fURNdKTNNJYsWFnBv3Yk7VndDVIXKENS9kJb7byAuolhZpISM_lH9FEZuyXb8dv3zokJLuynDQm9URZ5EY9x1UeuA
02-27 11:50:31.451: V/GCMBaseIntentService(30541): Releasing wakelock
02-27 11:50:31.451: D/CallbackProxy(30541): sendMessageToUiThreadSync Package=com.myCSOLApp message=112
02-27 11:50:31.491: D/TextLayoutCache(30541): Enable myanmar Zawgyi converter
02-27 11:50:31.491: D/TextLayoutCache(30541): Enable myanmar Zawgyi converter
02-27 11:50:31.491: D/TextLayoutCache(30541): Enable myanmar Zawgyi converter
02-27 11:50:31.516: D/TextLayoutCache(30541): Enable myanmar Zawgyi converter
02-27 11:50:31.516: D/TextLayoutCache(30541): Enable myanmar Zawgyi converter
02-27 11:50:31.521: D/TextLayoutCache(30541): Enable myanmar Zawgyi converter

I am trying it on a Samsung phone. The LogCat shows that all pending notifications have been dispatched. When I tried to call WL.Client.Push.__hasPendings() it returns false. But when another new notification comes now when the app is in foreground the old notification shows up. So what could be the possible problem ??

push-notification
ibm-mobilefirst
google-cloud-messaging
asked on Stack Overflow Feb 26, 2014 by Pushparaj Samant • edited Feb 27, 2014 by Pushparaj Samant

1 Answer

0

I worked it out by calling the android functions directly in my code.

if (WL.Client.Push){

    WL.Client.Push.onReadyToSubscribe = function(){
        alert("onReadyToSubscribe");

            alert("You said yes");
            WL.Client.Push.registerEventSourceCallback(
                    "myPush1", 
                    "PushAdapter", 
                    "PushEventSource1", 
                    pushNotificationReceived);

            if(!WL.Client.Push.isSubscribed("myPush1"))
                {
                    if(confirm('Do you allow CSOL to send notification to you?')) {
                        WL.Client.Push.subscribe("myPush1", {
                            onSuccess: doSubscribeSuccess,
                            onFailure: doSubscribeFailure
                        });
                }
                }
            else
                {
                    if(WL.Client.Push.__hasPendings()){
                    WL.Client.Push.__dispatchPendings();
                }
                cordova.exec(null, null, 'Push', 'dispatch', [ 'WL.Client.Push.__onmessage' ]);
                //cordova.exec("Push.dispatch", 'WL.Client.Push.__onmessage');
                }



    };

}
answered on Stack Overflow Feb 27, 2014 by Pushparaj Samant

User contributions licensed under CC BY-SA 3.0