push not initilizing when trying to create hybrid

2019-08-09 23:07发布

问题:

I am trying to implement push notifications using bluemix and mobilefirst. I have used the following links to implement

  1. http://www.ibm.com/developerworks/library/mo-cordova-push-app/
  2. http://mbaas-gettingstarted.ng.bluemix.net/hybrid#initialize-push -

When i run the the below code I am getting the following message in the console:

initPush called---------------- main.js:29 calling bluemix initialize with values---------------------- IBMBluemixHybrid.js:2956 [INFO] [DEFAULT] Hybrid initialize ["applicationid","applicationsecret","applicationroute"]

I neither see the device details reflected in the bluemix registered list. Can you please help me on this ?

var values = {
            applicationId:"applicationId",
            applicationRoute:"applicationRoute",
            applicationSecret:"applicationSecret"
        };
        console.log("initPush called---------------------------------");           
           console.log("calling bluemix initialize with values--------------------------------");

           IBMBluemix.initialize(values).then(function(status) {
              console.log("IBM Bluemix Initialized", status);
              return IBMPush.initializeService();
           }, function (err) {
              console.error("IBM Bluemix initialized failed" , err);
           }).then(function(pushObj) {
                  function pushReceived(info) {
                       console.log("registerListener - " + info.alert);
                       alert('got a push message! ' + info.alert);
                  }
              console.log("IBM Push Initialized", pushObj);
              push = pushObj;
              return push.registerDevice("LisaTest","Lisa123","pushReceived");
           }, function (err) {
              console.error("IBM Bluemix Push initialized failed" , err);
           }); 

回答1:

You need to replace "applicationId", "applicationRoute", and "applicationSecret" in the code

var values = {
        applicationId:"applicationId",
        applicationRoute:"applicationRoute",
        applicationSecret:"applicationSecret"
    };

with those obtained from your Bluemix backend application.

From the bluemix dashboard for your application click mobile options in the top right to see your ID and Route.

For the secret navigate to the Mobile Application Security dashboard from the link on the right, and your secret will be displayed on that page.