WL.Client.connect onSuccess 回调不会被调用

Posted

技术标签:

【中文标题】WL.Client.connect onSuccess 回调不会被调用【英文标题】:WL.Client.connect onSuccess callback does not get called 【发布时间】:2013-11-21 19:12:34 【问题描述】:

鉴于以下代码,onSuccess 不会在连接成功时被回调。我已经列出了事件序列的代码和日志输出。代码设置错了吗?在 initOptions 中将 connectOnStartup 设置为 false。此代码也在 Shell 项目中,其中 logcat 来自使用 Shell 的 Inner 项目:

function onConnectSuccess()
    console.log ("CSXMobile:onConnectSuccess");
    WL.Logger.debug("CSXMobile:onConnectSuccess");


function onConnectFailure()
    WL.Logger.debug("CSXMobile:onConnectFailure");


function disconnectDetected()
    WL.Logger.debug("CSXMobile:disconnectDetected");


function connectDetected()
    WL.Logger.debug("CSXMobile:connectDetected");


function wlCommonInit()

    WL.Logger.debug("CSXMobile:wlCommonInit");
    document.addEventListener(WL.Events.WORKLIGHT_IS_CONNECTED, connectDetected, false); 
    document.addEventListener(WL.Events.WORKLIGHT_IS_DISCONNECTED, disconnectDetected , false);

     WL.Client.connect(
         onSuccess: onConnectSuccess,
         onFailure: onConnectFailure
     );

从这里的日志中可以看出,正在调用并记录 wlCommonInit,但从未写入 onConnectSuccess 中的日志语句...

11-21 13:49:01.460: D/CSXMobileShellTest(6341): wlclient init started
11-21 13:49:01.460: D/CSXMobileShellTest(6341): Read cookies: null
11-21 13:49:01.460: D/CSXMobileShellTest(6341): CookieMgr read cookies: 
11-21 13:49:01.507: D/dalvikvm(6341): GC_CONCURRENT freed 311K, 4% free 11407K/11783K, paused 2ms+16ms, total 34ms
11-21 13:49:01.507: D/CordovaNetworkManager(6341): Connection Type: wifi
11-21 13:49:01.507: D/DroidGap(6341): onMessage(networkconnection,wifi)
11-21 13:49:01.507: D/DroidGap(6341): onMessage(spinner,stop)
11-21 13:49:01.507: D/CordovaLog(6341): CSXMobile:csxmobileDeviceReady
11-21 13:49:01.507: I/Web Console(6341): CSXMobile:csxmobileDeviceReady at file:///data/data/com.csx.CSXMobileShellTest/files/www/default/js/CSXMobile.js:172
11-21 13:49:01.538: D/CSXMobileShellTest(6341): CSXMobile:deviceOnline
11-21 13:49:01.546: D/CSXMobileShellTest(6341): before: app init onSuccess
11-21 13:49:01.546: D/CSXMobileShellTest(6341): CSXMobile:wlCommonInit
11-21 13:49:01.561: D/CSXMobileShellTest(6341): Request [https://myworklightserver/query]
11-21 13:49:01.585: D/CSXMobileShellTest(6341): after: app init onSuccess
11-21 13:49:01.585: D/CSXMobileShellTest(6341): added onPause event handler 
11-21 13:49:01.585: D/CSXMobileShellTest(6341): wlclient init success
11-21 13:49:01.858: D/CSXMobileShellTest(6341): isCustomResponse
11-21 13:49:01.858: D/CSXMobileShellTest(6341): isCustomResponse true
11-21 13:49:01.858: D/CSXMobileShellTest(6341): handleChallenge
11-21 14:14:57.796: D/DroidGap(6656): onMessage(spinner,stop)
11-21 14:15:08.975: D/CSXMobileShellTest(6656): Request [login]
11-21 14:15:09.132: D/CSXMobileShellTest(6656): Status =401
11-21 14:15:09.132: D/CSXMobileShellTest(6656): isCustomResponse
11-21 14:15:09.139: D/CSXMobileShellTest(6656): isCustomResponse false
11-21 14:15:09.147: D/CSXMobileShellTest(6656): Request [https://myworklightserver/query]
11-21 14:15:09.163: D/CSXMobileShellTest(6656): hideLogin
11-21 14:15:09.413: D/Cordova(6656): onPageFinished(file:///data/data/com.csx.CSXMobileShellTest/files/www/default/CSXMobileShellTest.html#testMainPage)
11-21 14:15:09.413: D/Cordova(6656): Trying to fire onNativeReady
11-21 14:15:09.413: D/DroidGap(6656): onMessage(onNativeReady,null)
11-21 14:15:09.413: D/DroidGap(6656): onMessage(onPageFinished,file:///data/data/com.csx.CSXMobileShellTest/files/www/default/CSXMobileShellTest.html#testMainPage)
11-21 14:15:09.475: D/CSXMobileShellTest(6656): Request [https://myworklightserver/query]
11-21 14:15:09.522: D/CSXMobileShellTest(6656): Request [https://myworklightserver/query]
11-21 14:15:09.616: D/CSXMobileShellTest(6656): isCustomResponse
11-21 14:15:09.616: D/CSXMobileShellTest(6656): isCustomResponse false
11-21 14:15:09.616: D/CSXMobileShellTest(6656): CSXMobile:connectDetected
11-21 14:15:09.647: D/CSXMobileShellTest(6656): response [https://myworklightserver/query] success: /*-secure-

【问题讨论】:

【参考方案1】:

我能够 ping 通 IBM 的联系人并获得反馈。我们正在结合 WL.Client.createChallengeHandler 来实现 challengeHandler。我省略的关键项目之一是执行 challengeHandler.submitSuccess();登录成功后。在成功的登录例程中添加该行后,一切正常。

【讨论】:

以上是关于WL.Client.connect onSuccess 回调不会被调用的主要内容,如果未能解决你的问题,请参考以下文章

IBM Worklight - 如何断开客户端连接?

尝试登录时发生与连接相关的异常

如何从 onSucces 类更改字符串的值

直接更新在 Worklight 6.1 中不起作用?

应用程序启动时与 Worklight 相关的错误消息

混合 Android 应用程序未连接到 MobileFirst 服务器