onReadyToSubscribe() 永远不会在原生 Android 上被调用

Posted

技术标签:

【中文标题】onReadyToSubscribe() 永远不会在原生 Android 上被调用【英文标题】:onReadyToSubscribe() is never getting called on native Android 【发布时间】:2015-04-28 14:00:20 【问题描述】:

使用基于适配器的身份验证登录后,我的任务活动上有两个按钮 1) 订阅 2) 取消订阅。

使用基于适配器的身份验证登录工作正常。

但是,onReadyToSubscribe() 从未被调用过,而且在 MobileFirst Operations Console 上我也看不到任何已注册的设备。我也尝试过创建一个挑战处理程序,但仍然没有成功。

任务活动

private void IBMPushNotificationRegisterEvent()

    client = WLClient.createInstance(this);
    push = client.getPush();

    PushListener listener = new PushListener(PushListener.MODE_CONNECT,this);

    push.setOnReadyToSubscribeListener(listener);
    client.connect(listener);




private void SubscribeNotification()
    client = WLClient.createInstance(this);
    client.getPush().subscribe("myandroid",new WLPushOptions(), new PushListener(PushListener.MODE_SUBSCRIBE,this));


private void UnSubscribeNotification()
    client = WLClient.createInstance(this);
    client.getPush().unsubscribe("myAndroid", new PushListener(PushListener.MODE_UNSUBSCRIBE,this));

推送监听器

public class PushListener implements WLOnReadyToSubscribeListener,WLResponseListener,WLEventSourceListener 

    public static final int MODE_CONNECT = 0;
    public static final int MODE_SUBSCRIBE = 1;
    public static final int MODE_UNSUBSCRIBE =2;

    private int mode ;
    private Context currentContext;

    public PushListener(int mode,Context ctx)
        this.mode = mode;
        currentContext = ctx;
    

    @Override
    public void onReadyToSubscribe() 

        WLClient.getInstance().getPush().registerEventSourceCallback("myAndroid", "TaskAdapter","PushEventSource", this );

    

    @Override
    public void onReceive(String arg0, String arg1) 

    

    @Override
    public void onSuccess(WLResponse wlResponse) 

        switch (mode)
            case MODE_CONNECT:
                // connect =true ;
                break;

            case MODE_SUBSCRIBE:
              TextView tt =  (TextView) (((Activity)currentContext).findViewById(R.id.tv_statusMsg));
                tt.setText("Subscribed");
                break;

            case MODE_UNSUBSCRIBE:
                // unsubscribe = true;
                break;

        
    

    @Override
    public void onFailure(WLFailResponse wlFailResponse) 
        switch (mode)
            case MODE_CONNECT:
                // connect =false ;
                break;

            case MODE_SUBSCRIBE:
                // subscribe = false;
                break;

            case MODE_UNSUBSCRIBE:
                //  unsubscribe = false;
                break;

        
    

任务适配器

WL.Server.createEventSource(
    name: 'PushEventSource',
    onDeviceSubscribe: 'deviceSubscribeFunc',
    onDeviceUnsubscribe: 'deviceUnsubscribeFunc',
    securityTest:'PushApplication-mobile-securityTest'


);

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


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




function submitNotification(userId, notificationText)

    var userSubscription = WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);

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

    var badgeDigit = 1;

    var notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, custom:"data");



    notification.MPNS.raw = 
        payload : payload : "You have a meeting in 5 minutes"
    ;

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

    WL.Server.notifyAllDevices(userSubscription, notification);

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



function onAuthRequired(headers, errorMessage)
    errorMessage = errorMessage ? errorMessage : null;
    WL.Logger.debug("my test");
    return 
        authRequired: true,
        errorMessage: errorMessage
    ;


function submitAuthentication(username, password)
   // if (username==="user" && password === "user")

        var userIdentity = 
                userId: username,
                displayName: username,
                attributes: 
                    foo: "bar"
                
        ;

        WL.Server.setActiveUser("SingleStepAuthRealm", userIdentity);

        return 
            authRequired: false,
            user :userIdentity
        ;
   // 

   // return onAuthRequired(null, "Invalid login credentials");



function getSecretData()
    return 
        secretData: "A secret data to invoke authentication"
    ;


function onLogout()
    WL.Logger.debug("Logged out");

AuthenticationConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<tns:loginConfiguration xmlns:tns="http://www.worklight.com/auth/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

        <!-- Licensed Materials - Property of IBM
             5725-I43 (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. -->  

     <staticResources>
     <!--  
            <resource id="logUploadServlet" securityTest="LogUploadServlet">
            <urlPatterns>/apps/services/loguploader*</urlPatterns>
        </resource>
        -->
        <resource id="subscribeServlet" securityTest="SubscribeServlet">
            <urlPatterns>/subscribeSMS*;/receiveSMS*;/ussd*</urlPatterns>
        </resource>

    </staticResources> 


     <securityTests>

        <customSecurityTest name="SubscribeServlet">
            <test realm="SubscribeServlet" isInternalUserID="true" isInternalDeviceID="true"/>
        </customSecurityTest>   

        <customSecurityTest name="SingleStepAuthAdapter-securityTest">
            <test isInternalUserID="true" realm="SingleStepAuthRealm"/>
        </customSecurityTest>

        <mobileSecurityTest  name="PushApplication-mobile-securityTest">
          <testUser realm="SingleStepAuthRealm"/>
          <testDeviceId provisioningType="none"/>
       </mobileSecurityTest >

    </securityTests> 

    <realms>

    <realm loginModule="AuthLoginModule" name="SingleStepAuthRealm">
            <className>com.worklight.integration.auth.AdapterAuthenticator</className>
            <parameter name="login-function" value="TaskAdapter.onAuthRequired"/>
            <parameter name="logout-function" value="TaskAdapter.onLogout"/>
        </realm>
        <realm name="SampleAppRealm" loginModule="StrongDummy">
            <className>com.worklight.core.auth.ext.FormBasedAuthenticator</className>
        </realm>

        <realm name="SubscribeServlet" loginModule="rejectAll">
            <className>com.worklight.core.auth.ext.HeaderAuthenticator</className>          
        </realm>

    </realms>

    <loginModules>
        <loginModule name="AuthLoginModule">
            <className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
        </loginModule>

        <loginModule name="StrongDummy" expirationInSeconds="-1">
            <className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
        </loginModule>

        <loginModule name="requireLogin" expirationInSeconds="-1">
            <className>com.worklight.core.auth.ext.SingleIdentityLoginModule</className>
        </loginModule>

        <loginModule name="rejectAll">
            <className>com.worklight.core.auth.ext.RejectingLoginModule</className>
        </loginModule>

    </loginModules>

</tns:loginConfiguration>

LogCat 日志

04-29 16:38:21.997  20704-20704/com.vdot.pushdemo D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-29 16:38:41.417  20704-20711/com.vdot.pushdemo I/jdwp﹕ Ignoring second debugger -- accepting and dropping
04-29 16:39:42.957  21735-21735/com.vdot.pushdemo I/System.out﹕ Sending WAIT chunk
04-29 16:39:42.957  21735-21735/com.vdot.pushdemo W/ActivityThread﹕ Application com.vdot.pushdemo is waiting for the debugger on port 8100...
04-29 16:39:42.967  21735-21741/com.vdot.pushdemo I/dalvikvm﹕ Debugger is active
04-29 16:39:43.167  21735-21735/com.vdot.pushdemo I/System.out﹕ Debugger has connected
04-29 16:39:43.167  21735-21735/com.vdot.pushdemo I/System.out﹕ waiting for debugger to settle...
04-29 16:39:43.367  21735-21735/com.vdot.pushdemo I/System.out﹕ waiting for debugger to settle...
04-29 16:39:43.567  21735-21735/com.vdot.pushdemo I/System.out﹕ waiting for debugger to settle...
04-29 16:39:43.567  21735-21741/com.vdot.pushdemo I/jdwp﹕ Ignoring second debugger -- accepting and dropping
04-29 16:39:43.777  21735-21735/com.vdot.pushdemo I/System.out﹕ waiting for debugger to settle...
04-29 16:39:43.977  21735-21735/com.vdot.pushdemo I/System.out﹕ waiting for debugger to settle...
04-29 16:39:44.167  21735-21735/com.vdot.pushdemo I/System.out﹕ waiting for debugger to settle...
04-29 16:39:44.367  21735-21735/com.vdot.pushdemo I/System.out﹕ waiting for debugger to settle...
04-29 16:39:44.577  21735-21735/com.vdot.pushdemo I/System.out﹕ debugger has settled (1321)
04-29 16:39:44.667  21735-21735/com.vdot.pushdemo D/Activity﹕ #1 setTransGradationModeColor false
04-29 16:39:44.727  21735-21735/com.vdot.pushdemo I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
    OpenGL ES Shader Compiler Version: E031.24.02.11
    Build Date: 09/12/14 Fri
    Local Branch: LA.3.6.1_20140912_070_patches
    Remote Branch:
    Local Patches:
    Reconstruct Branch:
04-29 16:39:44.737  21735-21735/com.vdot.pushdemo I/HWUI﹕ EGLImpl-HWUI Protected EGL context created
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ PartialUpdate status: Enabled
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ Left Align: 8
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ Width Align: 8
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ Top Align: 1
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ Height Align: 1
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ Min ROI Width: 1
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ Min ROI Height: 2
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ Needs ROI Merge: 1
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ Left Split=720
04-29 16:39:44.747  21735-21735/com.vdot.pushdemo I/qdutils﹕ Right Split=720
04-29 16:39:44.757  21735-21735/com.vdot.pushdemo D/OpenGLRenderer﹕ Enabling debug mode 0
04-29 16:40:03.527  21735-21735/com.vdot.pushdemo D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-29 16:40:04.077  21735-21735/com.vdot.pushdemo I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh
04-29 16:40:04.077  21735-21735/com.vdot.pushdemo W/dalvikvm﹕ VFY: unable to resolve virtual method 529: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
04-29 16:40:04.077  21735-21735/com.vdot.pushdemo D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000b
04-29 16:40:04.087  21735-21735/com.vdot.pushdemo W/GooglePlayServicesUtil﹕ Google Play services out of date.  Requires 7327000 but found 7099030
04-29 16:40:04.097  21735-21758/com.vdot.pushdemo W/com.worklight.common.Logger﹕ com.worklight.common.Logger.setContext(Context) must be called to fully enable debug log capture.  Currently, the 'capture' flag is set but the 'context' field is not.  This warning will only be printed once.
04-29 16:40:04.097  21735-21758/com.vdot.pushdemo D/GCMClientFactory﹕ GCMClientFactory.useGooglePlayServices in GCMClientFactory.java:38 :: Failed to use Google Play Services becuase the return code is 2
04-29 16:40:04.107  21735-21758/com.vdot.pushdemo D/GCMClientFactory﹕ GCMClientFactory.getInstance in GCMClientFactory.java:28 :: Using GCMHelperClient
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo I/dalvikvm﹕ Could not find method android.app.Notification$Builder.setColor, referenced from method com.worklight.wlclient.push.GCMIntentService.generateNotification
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo W/dalvikvm﹕ VFY: unable to resolve virtual method 239: Landroid/app/Notification$Builder;.setColor (I)Landroid/app/Notification$Builder;
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0039
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo D/dalvikvm﹕ DexOpt: couldn't find field Landroid/app/Notification;.visibility
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo W/dalvikvm﹕ VFY: unable to resolve instance field 31
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo D/dalvikvm﹕ VFY: replacing opcode 0x59 at 0x0029
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo D/dalvikvm﹕ DexOpt: couldn't find field Landroid/app/Notification;.publicVersion
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo I/dalvikvm﹕ DexOpt: unable to optimize instance field ref 0x001b at 0x62 in Lcom/worklight/wlclient/push/GCMIntentService;.notify
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo D/dalvikvm﹕ DexOpt: couldn't find field Landroid/app/Notification;.category
04-29 16:40:04.117  21735-21735/com.vdot.pushdemo I/dalvikvm﹕ DexOpt: unable to optimize instance field ref 0x000d at 0x72 in Lcom/worklight/wlclient/push/GCMIntentService;.notify
04-29 16:40:04.137  21735-21758/com.vdot.pushdemo W/GCMHelperClient﹕ GCMHelperClient.unregisterReceivers in GCMHelperClient.java:95 :: unregister:Receiver not registered: null
04-29 16:40:04.137  21735-21758/com.vdot.pushdemo W/GCMHelperClient﹕ GCMHelperClient.unregisterReceivers in GCMHelperClient.java:101 :: unregister:Receiver not registered: null
04-29 16:40:04.147  21735-21758/com.vdot.pushdemo W/com.worklight.wlclient.api.WLPush﹕ WLPush.unregisterReceivers in WLPush.java:792 :: unregisterReceivers:Receiver not registered: com.worklight.wlclient.api.WLPush$3@4370df08
04-29 16:40:04.197  21735-21735/com.vdot.pushdemo I/Choreographer﹕ Skipped 32 frames!  The application may be doing too much work on its main thread.
04-29 16:40:04.227  21735-21758/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-29 16:40:04.237  21735-21759/com.vdot.pushdemo I/System.out﹕ Thread-25957(ApacheHTTPLog):Reading from variable values from setDefaultValuesToVariables
04-29 16:40:04.257  21735-21759/com.vdot.pushdemo I/System.out﹕ Thread-25957(ApacheHTTPLog):isShipBuild true
04-29 16:40:04.257  21735-21759/com.vdot.pushdemo I/System.out﹕ Thread-25957(ApacheHTTPLog):SmartBonding Enabling is true, SHIP_BUILD is true, log to file is false, DBG is false
04-29 16:40:04.547  21735-21759/com.vdot.pushdemo I/System.out﹕ pool-3-thread-1 calls detatch()
04-29 16:40:06.777  21735-21758/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/invoke
04-29 16:40:06.977  21735-21760/com.vdot.pushdemo I/System.out﹕ pool-3-thread-2 calls detatch()
04-29 16:40:07.017  21735-21758/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-29 16:40:07.317  21735-21763/com.vdot.pushdemo I/System.out﹕ pool-3-thread-3 calls detatch()
04-29 16:40:07.387  21735-21758/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-29 16:40:07.817  21735-21765/com.vdot.pushdemo I/System.out﹕ pool-3-thread-4 calls detatch()
04-29 16:40:07.867  21735-21765/com.vdot.pushdemo D/com.demo.push﹕ Mode Connect Success
04-29 16:41:24.987  21735-21735/com.vdot.pushdemo D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-29 16:42:18.697  21735-21735/com.vdot.pushdemo D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-29 16:42:18.857  21735-21758/com.vdot.pushdemo D/WLClient﹕ WLClient.createInstance in WLClient.java:213 :: WLClient has already been created.
04-29 16:42:18.877  21735-21735/com.vdot.pushdemo W/GooglePlayServicesUtil﹕ Google Play services out of date.  Requires 7327000 but found 7099030
04-29 16:42:18.897  21735-21758/com.vdot.pushdemo D/GCMClientFactory﹕ GCMClientFactory.useGooglePlayServices in GCMClientFactory.java:38 :: Failed to use Google Play Services becuase the return code is 2
04-29 16:42:18.917  21735-21758/com.vdot.pushdemo D/GCMClientFactory﹕ GCMClientFactory.getInstance in GCMClientFactory.java:28 :: Using GCMHelperClient
04-29 16:42:18.937  21735-21758/com.vdot.pushdemo W/GCMHelperClient﹕ GCMHelperClient.unregisterReceivers in GCMHelperClient.java:95 :: unregister:Receiver not registered: null
04-29 16:42:18.967  21735-21758/com.vdot.pushdemo W/GCMHelperClient﹕ GCMHelperClient.unregisterReceivers in GCMHelperClient.java:101 :: unregister:Receiver not registered: null
04-29 16:42:18.997  21735-21758/com.vdot.pushdemo W/com.worklight.wlclient.api.WLPush﹕ WLPush.unregisterReceivers in WLPush.java:792 :: unregisterReceivers:Receiver not registered: com.worklight.wlclient.api.WLPush$3@439d5638
04-29 16:42:19.017  21735-21758/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-29 16:42:19.227  21735-21809/com.vdot.pushdemo I/System.out﹕ pool-3-thread-5 calls detatch()
04-29 16:42:19.277  21735-21809/com.vdot.pushdemo D/com.demo.push﹕ Mode Connect Success
04-29 16:42:22.257  21735-21735/com.vdot.pushdemo D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-29 16:42:22.427  21735-21758/com.vdot.pushdemo D/WLClient﹕ WLClient.createInstance in WLClient.java:213 :: WLClient has already been created.
04-29 16:42:22.477  21735-21758/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-29 16:42:22.567  21735-21758/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/query
04-29 16:42:22.897  21735-21815/com.vdot.pushdemo I/System.out﹕ pool-3-thread-6 calls detatch()
04-29 16:42:22.927  21735-21815/com.vdot.pushdemo D/com.demo.push﹕ Mode Connect Success
04-29 16:42:23.007  21735-21759/com.vdot.pushdemo I/System.out﹕ pool-3-thread-1 calls detatch()
04-29 16:42:23.027  21735-21759/com.vdot.pushdemo D/com.demo.push﹕ Mode Connect Success
04-29 16:42:33.637  21735-21735/com.vdot.pushdemo D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-29 16:42:33.877  21735-21758/com.vdot.pushdemo D/WLClient﹕ WLClient.createInstance in WLClient.java:213 :: WLClient has already been created.
04-29 16:42:33.897  21735-21735/com.vdot.pushdemo W/GooglePlayServicesUtil﹕ Google Play services out of date.  Requires 7327000 but found 7099030
04-29 16:42:33.917  21735-21758/com.vdot.pushdemo D/GCMClientFactory﹕ GCMClientFactory.useGooglePlayServices in GCMClientFactory.java:38 :: Failed to use Google Play Services becuase the return code is 2
04-29 16:42:33.927  21735-21758/com.vdot.pushdemo D/GCMClientFactory﹕ GCMClientFactory.getInstance in GCMClientFactory.java:28 :: Using GCMHelperClient
04-29 16:42:33.957  21735-21758/com.vdot.pushdemo W/GCMHelperClient﹕ GCMHelperClient.unregisterReceivers in GCMHelperClient.java:95 :: unregister:Receiver not registered: null
04-29 16:42:33.987  21735-21758/com.vdot.pushdemo W/GCMHelperClient﹕ GCMHelperClient.unregisterReceivers in GCMHelperClient.java:101 :: unregister:Receiver not registered: null
04-29 16:42:34.007  21735-21758/com.vdot.pushdemo W/com.worklight.wlclient.api.WLPush﹕ WLPush.unregisterReceivers in WLPush.java:792 :: unregisterReceivers:Receiver not registered: com.worklight.wlclient.api.WLPush$3@43a4d3d0
04-29 16:42:34.037  21735-21758/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-29 16:42:34.337  21735-21760/com.vdot.pushdemo I/System.out﹕ pool-3-thread-2 calls detatch()
04-29 16:42:34.367  21735-21760/com.vdot.pushdemo D/com.demo.push﹕ Mode Connect Success

更新日志

04-30 09:22:38.027  30652-30652/com.vdot.pushdemo I/Choreographer﹕ Skipped 34 frames!  The application may be doing too much work on its main thread.
04-30 09:22:38.037  30652-31058/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-30 09:22:38.047  30652-31059/com.vdot.pushdemo I/System.out﹕ Thread-26598(ApacheHTTPLog):Reading from variable values from setDefaultValuesToVariables
04-30 09:22:38.077  30652-31059/com.vdot.pushdemo I/System.out﹕ Thread-26598(ApacheHTTPLog):isShipBuild true
04-30 09:22:38.077  30652-31059/com.vdot.pushdemo I/System.out﹕ Thread-26598(ApacheHTTPLog):SmartBonding Enabling is true, SHIP_BUILD is true, log to file is false, DBG is false
04-30 09:22:38.297  30652-31059/com.vdot.pushdemo I/System.out﹕ pool-3-thread-1 calls detatch()
04-30 09:22:40.617  30652-31058/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/invoke
04-30 09:22:40.737  30652-31064/com.vdot.pushdemo I/System.out﹕ pool-3-thread-2 calls detatch()
04-30 09:22:40.767  30652-31058/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-30 09:22:40.897  30652-31067/com.vdot.pushdemo I/System.out﹕ pool-3-thread-3 calls detatch()
04-30 09:22:40.947  30652-31058/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-30 09:22:41.197  30652-31069/com.vdot.pushdemo I/System.out﹕ pool-3-thread-4 calls detatch()
04-30 09:22:41.227  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.updateToken in WLPush.java:521 :: Registering at the GCM server.
04-30 09:22:41.237  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.clearSubscribedEventSources in WLPush.java:596 :: Clearing notification subscriptions.
04-30 09:22:41.247  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.clearSubscribedTags in WLPush.java:607 :: Clearing tag notification subscriptions.
04-30 09:22:41.257  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.updateSubscribedTags in WLPush.java:635 :: Updating tag notification subscriptions.
04-30 09:22:41.257  30652-31069/com.vdot.pushdemo D/com.demo.push﹕ Mode Connect Success
04-30 09:22:41.527  30652-31058/com.vdot.pushdemo D/GCMAPIClient﹕ GCMAPIClient$1.doInBackground in GCMAPIClient.java:45 :: Successfully registered with GCM using Google Play Services. Returned deviceToken:APA91bHvvCrMUQr-zI-CEjbmu3R7r7s_f9jPAMyBslPnQd16DPTveB96nzvYXRRIrzv_HbbMLdPitz-VjmhFKSZnFfC349IRSADxmfDm0h4ps82YUeTAGMUepUZhwrb7V24ExHLilp0qmcryQcn3pnmCOhPuJc6vZQ
04-30 09:22:41.537  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.updateTokenCallback in WLPush.java:756 :: Push notification device token has changed, Updating on server [serverToken: null, deviceToken: APA91bHvvCrMUQr-zI-CEjbmu3R7r7s_f9jPAMyBslPnQd16DPTveB96nzvYXRRIrzv_HbbMLdPitz-VjmhFKSZnFfC349IRSADxmfDm0h4ps82YUeTAGMUepUZhwrb7V24ExHLilp0qmcryQcn3pnmCOhPuJc6vZQ]
04-30 09:22:41.567  30652-31058/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/notifications
04-30 09:22:42.407  30652-31078/com.vdot.pushdemo I/System.out﹕ pool-3-thread-5 calls detatch()
04-30 09:22:49.337  30652-31078/com.vdot.pushdemo D/com.demo.push﹕ onReadyToSubscribe
04-30 09:23:24.177  30652-30652/com.vdot.pushdemo D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-30 09:23:24.337  30652-31058/com.vdot.pushdemo D/WLClient﹕ WLClient.createInstance in WLClient.java:213 :: WLClient has already been created.
04-30 09:23:24.377  30652-31058/com.vdot.pushdemo D/GCMClientFactory﹕ GCMClientFactory.getInstance in GCMClientFactory.java:25 :: Using GCMAPIClient
04-30 09:23:24.397  30652-31058/com.vdot.pushdemo W/com.worklight.wlclient.api.WLPush﹕ WLPush.unregisterReceivers in WLPush.java:792 :: unregisterReceivers:Receiver not registered: com.worklight.wlclient.api.WLPush$3@439f2148
04-30 09:23:24.427  30652-31058/com.vdot.pushdemo D/wl.request﹕ WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://10.136.78.232:10080/MFPushDemo/apps/services/api/AndroidPushDemo/Androidnative/init
04-30 09:23:24.617  30652-31085/com.vdot.pushdemo I/System.out﹕ pool-3-thread-6 calls detatch()
04-30 09:23:24.657  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.updateToken in WLPush.java:521 :: Registering at the GCM server.
04-30 09:23:24.677  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.clearSubscribedEventSources in WLPush.java:596 :: Clearing notification subscriptions.
04-30 09:23:24.687  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.updateSubscribedEventSources in WLPush.java:614 :: Updating notification subscriptions.
04-30 09:23:24.697  30652-31085/com.vdot.pushdemo D/com.demo.push﹕ Mode Connect Success
04-30 09:23:24.697  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.clearSubscribedTags in WLPush.java:607 :: Clearing tag notification subscriptions.
04-30 09:23:24.707  30652-31058/com.vdot.pushdemo D/com.worklight.wlclient.api.WLPush﹕ WLPush.updateSubscribedTags in WLPush.java:635 :: Updating tag notification subscriptions.
04-30 09:23:24.807  30652-31058/com.vdot.pushdemo D/GCMAPIClient﹕ GCMAPIClient$1.doInBackground in GCMAPIClient.java:45 :: Successfully registered with GCM using Google Play Services. Returned deviceToken:APA91bHvvCrMUQr-zI-CEjbmu3R7r7s_f9jPAMyBslPnQd16DPTveB96nzvYXRRIrzv_HbbMLdPitz-VjmhFKSZnFfC349IRSADxmfDm0h4ps82YUeTAGMUepUZhwrb7V24ExHLilp0qmcryQcn3pnmCOhPuJc6vZQ
04-30 09:23:24.817  30652-31086/com.vdot.pushdemo D/com.demo.push﹕ onReadyToSubscribe
04-30 09:24:08.677  30652-30652/com.vdot.pushdemo D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-30 09:24:08.877  30652-31058/com.vdot.pushdemo D/WLClient﹕ WLClient.createInstance in WLClient.java:213 :: WLClient has already been created.
04-30 09:24:08.917  30652-31058/com.vdot.pushdemo D/GCMClientFactory﹕ GCMClientFactory.getInstance in GCMClientFactory.java:25 :: Using GCMAPIClient
04-30 09:24:08.927  30652-31058/com.vdot.pushdemo W/com.worklight.wlclient.api.WLPush﹕ WLPush.unregisterReceivers in WLPush.java:792 :: unregisterReceivers:Receiver not registered: com.worklight.wlclient.api.WLPush$3@43a356a0

分级

dependencies 
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:7.0.0'

【问题讨论】:

因为您说您已经登录到应用程序,请尝试不使用事件源上的 securityTest。这不是必需的。另外,在应用启动时添加 LogCat 日志,这可能与 GCM 配置有关。 删除了安全测试,但仍然没有运气。昨天一名 IBM 员工对我的机器进行了远程操作,但仍然无法找出问题所在。 IBM 告诉我要创建一个全新的推送应用程序,而不是使用现有的应用程序,看看它是否正常工作。 LogCat 日志怎么样? 嗨 Idan,创建了一个全新的应用程序并发布了 logcat 日志。有趣的是 onReadyToSubscribe 首次触发,我在控制台的应用程序选项卡上看到了该应用程序,一段时间后它停止了再次工作。我也尝试禁用我的防病毒软件.. 【参考方案1】:

从 LogCat 日志看来,您使用的是过时的 Google Play 服务:

04-29 16:42:33.897 21735-21735/com.vdot.pushdemo W/GooglePlayServicesUtil﹕Google Play 服务已过时。需要 7327000 却发现 7099030 04-29 16:42:33.917 21735-21758/com.vdot.pushdemo D/GCMClientFactory﹕ GCMClientFactory.useGooglePlayServices 在 GCMClientFactory.java:38:: 无法使用 Google Play 服务,因为返回码是 2

推送通知需要 Google Play 服务。如果这个服务初始化失败,push可能确实不起作用。

打开 Android SDK 管理器,更新 Play Services 组件并确保应用程序已正确配置以使用它。然后再试一次。

【讨论】:

嗨 Idan,由 SDK 中的 Google play 服务更新。更新后我去了 Android\android sdk\extras\google\m2repository\com\google\android\gms\play-services 并检查了我的版本号。我有最新的 7.3.0,但是当我将 7.3.0 放入 build.gradle 时,它​​要求我更新设备上的 google play 服务。我没有授权更新此设备,所以我继续将版本号更改为 7.0.0。注册已成功,但收到“无法订阅,服务器上未更新通知令牌”之类的消息。也发布了更新日志。

以上是关于onReadyToSubscribe() 永远不会在原生 Android 上被调用的主要内容,如果未能解决你的问题,请参考以下文章

猫鼬承诺永远不会到达 .then()

为啥 IsDialogMessage() 可能永远不会返回?

CATransaction 完成块永远不会触发

AVPlayer seekToTime 永远不会完成

如果位置服务关闭,CLLocationManager 永远不会更新

为啥 eof() 永远不会返回 true?