我有一个Ionic项目,我添加了一个推送通知回调处理程序,如官方文档中所述(我希望在应用程序内部和通知到达时有一些警告),但它永远不会被调用。
WL.Client.Push.registerEventSourceCallback(
"myPush",
"PushAdapter",
"PushEventSource",
pushNotificationReceived);
这里的问题是我必须要调用pushNotificationReceived函数吗?我尝试在index.js和控制器内部作为函数,但我没有成功。 感谢您的帮助
答案 0 :(得分:0)
您是否查看了推送通知的示例应用程序? 该示例演示了推送通知API的实现。 https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/notifications/push-notifications-overview/push-notifications-in-hybrid-applications/event-source-notifications-in-hybrid-applications/
请参阅提供的main.js文件:https://github.com/MobileFirst-Platform-Developer-Center/EventSourceNotifications/blob/release71/apps/HybridEventSource/common/js/main.js
答案 1 :(得分:0)
在“成功连接移动第一台服务器”之后,您必须在app.js文件中的ionic中包含回调函数。
WLAuthorizationManager.obtainAccessToken().then(
function (response) {
//alert("successfully obtained a token from the server");
MFPPush.initialize (
function(successResponse) {
//alert("Successfully intialized");
MFPPush.registerNotificationsCallback(notificationReceived);
},
function(failureResponse) {
console.log("Failed to initialize");
}
);
MFPPush.isPushSupported (
function(successResponse) {
//alert("Push Supported: " + successResponse);
},
function(failureResponse) {
console.log("Failed to get push support status");
}
);
MFPPush.registerDevice(
function(successResponse) {
//alert("Successfully registered");
},
function(failureResponse) {
console.log("Failed to register");
}
);
function notificationReceived(message) {
alert(JSON.stringify(message.alert));
}
},
function(response) {
//alert("res"+JSON.stringify(response));
console.log("Unable to obtain a token from the server: " + JSON.stringify(response));
if(JSON.stringify(response.status) == 403){
console.log("The Application is disabled on this Device");
ionic.Platform.exitApp();
}
}
);