身份验证后未显示IBM Worklight推送通知

时间:2014-02-26 10:10:44

标签: push-notification ibm-mobilefirst google-cloud-messaging

嗨,我有一个非常奇怪的推送通知问题。我尝试了提供的PushNotification项目,一切都很好。但是现在在我的应用程序中,当我尝试以类似的方式实现它时,我遇到了这个问题。 所以我所做的是在我的main.js文件中,我为用户添加了以下代码,以便能够订阅。

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 
        };
    }

当我将应用程序放在前台时,一切正常。或者,当我按下手机上的主页按钮时,我会收到通知并点击通知重新打开应用程序并显示特定通知。但是当我按下后退按钮或我退出时我收到通知,点击通知会将我带回应用程序并要求我登录。但是一旦我登录,我就无法看到通知。 我正在使用自定义登录模块,它根据硬编码字符串值检查用户名密码。 这是日志

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

我在三星手机上试试。 LogCat显示已分派所有挂起的通知。当我尝试调用WL.Client.Push。 _ _hasPendings()时,它返回false。但是,当应用程序处于前台时,当另一个新通知出现时,旧通知会显示出来。那可能是什么问题?

1 个答案:

答案 0 :(得分:0)

我通过直接在我的代码中调用android函数来解决这个问题。

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');
                }



    };

}