我正在嘗試將推送通知集成到我的MobileFirst項目中。我成功地連接到MobileFirst服務器,但是,當我嘗試訂閱我的設備以進行推送通知時,我在控制檯中收到以下錯誤,無法訂閱,通知令牌未在服務器上更新。IBM Worklight 6.3 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":"[email protected]"},"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":"[email protected]"},"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
如果您不修改示例(除了添加自己的GCM密鑰和發件人ID),它是否適合您? –
示例代碼也不適用於我的機器,但是當我在我的同事Mac機器上測試時,它在那裏工作。 – WebSwami