MobileFirst和Ionic Push通知回调

时间:2016-02-22 10:10:01

标签: ibm-mobilefirst

我有一个Ionic项目,我添加了一个推送通知回调处理程序,如官方文档中所述(我希望在应用程序内部和通知到达时有一些警告),但它永远不会被调用。

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

这里的问题是我必须要调用pushNotificationReceived函数吗?我尝试在index.js和控制器内部作为函数,但我没有成功。 感谢您的帮助

2 个答案:

答案 0 :(得分:0)

答案 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();
            }
        }
     );