IBM Worklight 6.3 MobileFirst推送通知:无法订阅

时间:2015-12-31 11:15:06

标签: android notifications push-notification ibm-mobilefirst

我正在尝试在我的MobileFirst项目中集成推送通知。我已成功连接到MobileFirst服务器但是,当我尝试订阅我的设备以进行推送通知时,我在控制台中收到以下错误,无法订阅,服务器上的通知令牌未更新。

有可能,我无法触发WL.Client.Push.onReadyToSubscribe功能。

请查找代码以及日志消息:

客户端代码(main.js):

function wlCommonInit(){

    // Common initialization code goes here
    HybridJS.init();
    WL.Client.connect({onSuccess: connectSuccess, onFailure: connectFailure});
}

function connectSuccess() {
    alert("Successfully connected to MobileFirst Server.");
}

function connectFailure() {
    alert ("Failed connecting to MobileFirst Server.");
    WL.SimpleDialog.show("Push Notifications", "Failed connecting to MobileFirst Server. Try again later.", 
            [{
                text : 'Reload',
                handler : WL.Client.reloadapp
            },
            {
                text: 'Close',
                handler : function() {}
            }]
        );
}


alert("WL.Client.Push : "+WL.Client.Push);
//if (WL.Client.Push){
    WL.Client.Push.onReadyToSubscribe = function() {
        alert("onReadyToSubscribe");

        WL.Client.Push.registerEventSourceCallback(
            "myPush",
            "PushAdapter",
            "PushEventSource",
            pushNotificationReceived);
    };

//}

function isPushSupported() {
    alert("In isPushSupported() function");
    var isSupported = false;
    isSupported = WL.Client.Push.isPushSupported();
    alert(isSupported);
}

//--------------------------------- Subscribe ------------------------------------
function doSubscribe() {
    alert("In do subscribe");
    WL.Client.Push.subscribe("myPush", {
        onSuccess: doSubscribeSuccess,
        onFailure: doSubscribeFailure
    });
}

function doSubscribeSuccess() {
    alert("doSubscribeSuccess");
}
function doSubscribeFailure() {
    alert("doSubscribeFailure");
}

//------------------------------- Handle received notification ---------------------------------------
function pushNotificationReceived(props, payload) {
    alert("pushNotificationReceived invoked");
    alert("props :: " + JSON.stringify(props));
    alert("payload :: " + JSON.stringify(payload));
}

遵循的步骤和使用的其余文件与链接https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-6-3/notifications/push-notifications-hybrid-applications/中提供的示例项目相同

记录消息:

12-31 05:26:01.694: D/NONE(9035): Clearing notification subscriptions.
12-31 05:26:01.710: D/NONE(9035): Clearing tag notification subscriptions.
12-31 05:26:01.730: D/NONE(9035): Send new server notification token id.
12-31 05:26:01.742: D/NONE(9035): Updating tag notification subscriptions.
12-31 05:26:01.766: D/GCMHelperUtil(9035): GCMHelperUtil.register in GCMHelperUtil.java:34 :: Registering with GCM server with senderId: 390717241217
12-31 05:26:01.790: D/NONE(9035): response [/apps/services/api/MyProject/android/init] success: /*-secure-


12-31 05:26:01.790: D/NONE(9035): {"userPrefs":{},"WL-Authentication-Success":{"wl_directUpdateRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null","deviceId":"null"},"wl_remoteDisableRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null","deviceId":"null"},"PushAppRealm":{"userId":"admin","attributes":{},"isUserAuthenticated":1,"displayName":"admin","deviceId":"admin"},"wl_antiXSRFRealm":{"userId":"iff3d23vg53u04sd8gf9vsajeo","attributes":{},"isUserAuthenticated":1,"displayName":"iff3d23vg53u04sd8gf9vsajeo","deviceId":"iff3d23vg53u04sd8gf9vsajeo"},"wl_deviceNoProvisioningRealm":{"userId":"5bd68445-7e7f-3ece-9072-6d4e5d910bff","attributes":{"mobileClientData":"com.worklight.core.auth.ext.MobileClientData@77b4a0fd"},"isUserAuthenticated":1,"displayName":"5bd68445-7e7f-3ece-9072-6d4e5d910bff","deviceId":"5bd68445-7e7f-3ece-9072-6d4e5d910bff"}},"notificationSubscriptionState":{"tags":["Push.ALL"],"credentials":"390717241217"},"gadgetProps":{"ENVIRONMENT":"android"},"userInfo":{"SubscribeServlet":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null,"deviceId":null},"wl_directUpdateRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null","deviceId":"null"},"SingleStepAuthRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null,"deviceId":null},"WorklightConsole":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null,"deviceId":null},"wl_deviceAutoProvisioningRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null,"deviceId":null},"wl_deviceNoProvisioningRealm":{"userId":"5bd68445-7e7f-3ece-9072-6d4e5d910bff","attributes":{"mobileClientData":"com.worklight.core.auth.ext.MobileClientData@77b4a0fd"},"isUserAuthenticated":1,"displayName":"5bd68445-7e7f-3ece-9072-6d4e5d910bff","deviceId":"5bd68445-7e7f-3ece-9072-6d4e5d910bff"},"wl_anonymousUserRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null,"deviceId":null},"wl_authenticityRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null,"deviceId":null},"SampleAppRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null,"deviceId":null},"wl_remoteDisableRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null","deviceId":"null"},"PushAppRealm":{"userId":"admin","attributes":{},"isUserAuthenticated":1,"displayName":"admin","deviceId":"admin"},"wl_antiXSRFRealm":{"userId":"iff3d23vg53u04sd8gf9vsajeo","attributes":{},"isUserAuthenticated":1,"displayName":"iff3d23vg53u04sd8gf9vsajeo","deviceId":"iff3d23vg53u04sd8gf9vsajeo"},"myserver":{"userId":"admin","attributes":{},"isUserAuthenticated":1,"displayName":"admin","deviceId":"admin"}}}*/
12-31 05:26:01.830: D/NONE(9035): wlclient connect success


12-31 05:30:09.419: E/NONE(9035): Can't subscribe, notification token is not updated on the server

1 个答案:

答案 0 :(得分:0)

斯瓦米,你的问题与代码无关。这是与worklight配置相关的问题。这个代码/示例对我有用。