问题1:
我正在尝试使用IBM worklight实现基于标记的推送通知。正如培训材料中所建议的,我在应用程序描述符文件中添加了标签。此外,我已在main.js
文件中订阅了该特定标记名。
遵循的步骤:
WL.Client.PushsubscribeTag("OFFERS", {onSuccess:doSubscribeSuccess , onFailure: doSubscribeFailure})
函数中使用WL.Client.Push.onReadyToSubscribe
订阅了该代码。WL.client.Push.onMessage(props,payload)
来处理收到的通知。doSubscribeMethod
中的main.js
(已附加),但不会调用回调方法doSubscribeSuccess。Failed to send Notification Reason FPWSE0009E. No devices found
问题2: WL.Server.CreateEventsource将在何时调用此过程。
注意:遵循有关推送通知配置的所有步骤,并为基于事件的推送提供的示例代码正常工作。
修改 我在下面的日志片段中附加了logcat以查找错误信息。
07-18 18:19:19.253:D / CordovaLog(1081):file:///android_asset/www/default/worklight/cordova.js:第1061行:processMessage失败:Stack:TypeError:无法读取属性& #39; hideView'未定义的 07-18 18:19:19.253:D / CordovaLog(1081):at wlEnvInit(file:///android_asset/www/default/js/main.js:77:78) 07-18 18:19:19.253:D / CordovaLog(1081):at file:///android_asset/www/default/worklight/worklight.js:7638:5 07-18 18:19:19.253:D / CordovaLog(1081):at Object.onSuccess(file:///android_asset/www/default/worklight/worklight.js:7665:5) 07-18 18:19:19.253:D / CordovaLog(1081):在finalizeInit(文件:///android_asset/www/default/worklight/worklight.js:6972:15) 07-18 18:19:19.253:D / CordovaLog(1081):at Object。 (文件:///android_asset/www/default/worklight/worklight.js:7812:7) 07-18 18:19:19.253:D / CordovaLog(1081):at Object。 (文件:///android_asset/www/default/worklight/wljq.js:1202:33) 07-18 18:19:19.253:D / CordovaLog(1081):at file:///android_asset/www/default/worklight/wljq.js:1047:30 07-18 18:19:19.253:D / CordovaLog(1081):at Object.resolveWith(file:///android_asset/www/default/worklight/wljq.js:1158:7) 07-18 18:19:19.253:D / CordovaLog(1081):at Object.resolve(file:///android_asset/www/default/worklight/wljq.js:1247:34) 07-18 18:19:19.253:D / CordovaLog(1081):at deviceIDSuccessCallback(file:///android_asset/www/default/worklight/worklight.js:7732:22) 07-18 18:19:19.253:I / Web Console(1081):processMessage失败:Stack:TypeError:无法读取属性' hideView'未定义的 07-18 18:19:19.253:I / Web Console(1081):at wlEnvInit(file:///android_asset/www/default/js/main.js:77:78) 07-18 18:19:19.253:I / Web Console(1081):at file:///android_asset/www/default/worklight/worklight.js:7638:5 07-18 18:19:19.253:I / Web Console(1081):at Object.onSuccess(file:///android_asset/www/default/worklight/worklight.js:7665:5) 07-18 18:19:19.253:I / Web Console(1081):在finalizeInit(文件:///android_asset/www/default/worklight/worklight.js:6972:15) 07-18 18:19:19.253:I / Web Console(1081):at Object。 (文件:///android_asset/www/default/worklight/worklight.js:7812:7) 07-18 18:19:19.253:I / Web Console(1081):at Object。 (文件:///android_asset/www/default/worklight/wljq.js:1202:33) 07-18 18:19:19.253:I / Web Console(1081):at file:///android_asset/www/default/worklight/wljq.js:1047:30 07-18 18:19:19.253:I / Web Console(1081):at Object.resolveWith(file:///android_asset/www/default/worklight/wljq.js:1158:7) 07-18 18:19:19.253:I / Web Console(1081):at Object.resolve(file:///android_asset/www/default/worklight/wljq.js:1247:34) 07-18 18:19:19.253:I / Web Console(1081):at deviceIDSuccessCallback(file:///android_asset/www/default/worklight/worklight.js:7732:22)at file:/// android_asset / www /default/worklight/cordova.js:1061 07-18 18:19:19.263:D / CordovaLog(1081):file:///android_asset/www/default/worklight/cordova.js:第1062行:processMessage失败:消息:S01 DeviceAuth365622402 s90e2f8ab-3e50-3564-921f -b4887579e4a2 07-18 18:19:19.263:I / Web Console(1081):processMessage failed:消息:S01 DeviceAuth365622402 s90e2f8ab-3e50-3564-921f-b4887579e4a2 at file:///android_asset/www/default/worklight/cordova.js :1062 07-18 18:19:19.313:E / NONE(1081):成功建立了与MBaaS的连接 07-18 18:19:19.323:W / PluginManager(1081):THREAD WARNING:对LoggerPlugin.log的exec()调用阻塞了主线程22ms。插件应该使用CordovaInterface.getThreadPool()。 07-18 18:19:19.383:D / NONE(1081):Ganesh doSubscribe featurefalse 07-18 18:19:19.443:W / PluginManager(1081):THREAD WARNING:对LoggerPlugin.log的exec()调用阻塞了主线程19ms。插件应该使用CordovaInterface.getThreadPool()。 07-18 18:19:19.453:D / NONE(1081):输入了Ganesh doSubscribe功能 07-18 18:19:19.484:W / PluginManager(1081):THREAD WARNING:对LoggerPlugin.log的exec()调用阻塞了主线程40ms。插件应该使用CordovaInterface.getThreadPool()。 07-18 18:19:19.543:E / NONE(1081):无法订阅,服务器上的通知令牌未更新 07-18 18:19:19.563:D / dalvikvm(1081):GC_CONCURRENT释放426K,26%免费3050K / 4080K,暂停14ms + 35ms,总计195ms
答案 0 :(得分:0)
如果您的应用程序基于标记通知示例,则不会使用WL.Server.createEventSource
,因为该API方法用于基于事件源的通知,而不是基于标记的通知。
确保您关注基于标记的通知的正确示例,可在此处找到:https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-0/notifications/push-notifications-hybrid-applications/tag-based-notifications/
接下来,目前尚不清楚您是在iOS或Android上进行测试,以及是否已正确设置。请确保您拥有:https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-0/notifications/push-notifications-hybrid-applications/
现在,您需要确保遵循示例应用程序(download link)的实现步骤。请查看示例中的main.js实现代码段:
//---------------------------- Check if push support is available ----------------------
function isPushSupported() {
var isSupported = false;
if (WL.Client.Push){
isSupported = WL.Client.Push.isPushSupported();
}
WL.SimpleDialog.show("Tag Notifications", JSON.stringify(isSupported), [ {
text : 'Close',
handler : function() {}
}
]);
}
//---------------------------- Set up push notifications -------------------------------
if (WL.Client.Push) {
WL.Client.Push.onReadyToSubscribe = function() {
WL.SimpleDialog.show("Tag Notifications", "Ready to subscribe", [ {
text : 'Close',
handler : function() {}
}
]);
$('.subscribeToTagButton').removeAttr('disabled');
$('.unsubscribeFromTagButton').removeAttr('disabled');
};
}
// --------------------------------- Subscribe to tag ----------------------------------
function subscribeToSampleTag1() {
WL.Client.Push.subscribeTag("sample-tag1", {
onSuccess: subscribeTagSuccess,
onFailure: subscribeTagFailure
});
}
function subscribeToSampleTag2() {
WL.Client.Push.subscribeTag("sample-tag2", {
onSuccess: subscribeTagSuccess,
onFailure: subscribeTagFailure
});
}
function subscribeTagSuccess() {
WL.SimpleDialog.show("Tag Notifications", "Subscribed to tag", [ {
text : 'Close',
handler : function() {}
}
]);
}
function subscribeTagFailure() {
WL.SimpleDialog.show("Tag Notifications", "Failed subscribing to tag", [ {
text : 'Close',
handler : function() {}
}
]);
}
// ------------------------------- Check if subscribed ---------------------------------
function isSubscribedToTags() {
var subscribedTagsSample1 = WL.Client.Push.isTagSubscribed("sample-tag1");
var subscribedTagsSample2 = WL.Client.Push.isTagSubscribed("sample-tag2");
WL.SimpleDialog.show("Tag Notifications", 'sample-tag1: ' + subscribedTagsSample1 + '\n' + 'sample-tag2: ' + subscribedTagsSample2, [ {
text : 'Close',
handler : function() {}
}
]);
}
// ------------------------------- Unsubscribe from tag --------------------------------
function unsubscribeFromSampleTag1() {
WL.Client.Push.unsubscribeTag("sample-tag1", {
onSuccess: unsubscribeTagSuccess,
onFailure: unsubscribeTagFailure
});
}
function unsubscribeFromSampleTag2() {
WL.Client.Push.unsubscribeTag("sample-tag2", {
onSuccess: unsubscribeTagSuccess,
onFailure: unsubscribeTagFailure
});
}
function unsubscribeTagSuccess(response) {
WL.SimpleDialog.show("Tag Notifications", "Unsubscribe from tag", [ {
text : 'Close',
handler : function() {}
}
]);
}
function unsubscribeTagFailure(response) {
WL.SimpleDialog.show("Tag Notifications", "Failed subscribing from tag", [ {
text : 'Close',
handler : function() {}
}
]);
}
//------------------------------- Handle received notification ---------------------------------------
WL.Client.Push.onMessage = function (props, payload) {
WL.SimpleDialog.show("Tag Notifications", "Provider notification data: " + JSON.stringify(props), [ {
text : 'Close',
handler : function() {
WL.SimpleDialog.show("Tag Notifications", "Application notification data: " + JSON.stringify(payload), [ {
text : 'Close',
handler : function() {}
}]);
}
}]);
};