0

Currently developing a Cordova app and wanted to use the IBM Bluemix Push Notification service to send user based push notifications.

According to the documentation here, seems like the first step is to call MFPPush.initialize(appGuid, clientSecret), which I tried to do. But this function is not present in the plugin interface and therefore I get an 'undefined' error when running the app.

Moreover, the doc also talks about calling MFPPush.registerDevice({},success,failure,userId). However, when I look at the plugin javascript interface, it only takes 3 parameters.

Could someone please give some advice to help me sort this out?

Thanks.

Johan Mereaux
  • 143
  • 11

2 Answers2

0

I just ran the Bluemix Cordova hellopush sample which should help you out. Make sure you follow the directions in the README, and make sure to change the route and guid in your index.js (it should look something like this):

route: "http://imfpush.ng.bluemix.net",
guid: "djkslk3j2-4974-4324-8e82-421c02ce847c",

You will be able to find the route and guid in your Push Notifications service credentials.


After running it by following the directions (and ensuring that you have GCM / APNS set up correctly for whatever platform you are using), you should be greeted with this screen after clicking register:

joe
  • 2,468
  • 2
  • 12
  • 19
  • Let me know if this works for you or if you run into any issues. – joe Sep 21 '16 at 13:32
  • I am sorry but your sample does not talk about user based notifications at all. I have no problem doing device base notifications. – Johan Mereaux Sep 21 '16 at 13:37
  • Okay, I see what problem you're running into. Let me get in contact with the push team to get some answers. – joe Sep 21 '16 at 14:18
  • So, I just talked with the push team. At this time, configuring the `userId` from Cordova is not supported. There is a workaround where you could use the REST API (Swagger Docs: https://mobile.ng.bluemix.net/imfpushrestapidocs/) to code it, but you need to pass a valid client secret request header (e.g. `req.addheader{"clientSecret":"push service client secret"}`) to your request. Let me know if you decide to do that / if you need any help. There will be improvements in the Cordova user experience in the near future. – joe Sep 21 '16 at 17:10
  • Thanks a lot for the info Joe. I planned to use user based notifications for an ongoing customer project (since it seems to be available when looking at the documentation of the bluemix service, which has to be updated apparently :-) Would you have any date when this feature will be added to the Cordova plugin? Regarding the alternative you propose, would you have any sample that showcases how to register and receive a user based notification from a Cordova app? Thanks – Johan Mereaux Sep 22 '16 at 07:58
  • Hi Johan, I talked with the Push team again, and they recommend waiting until this functionality is built into the Cordova SDK. The workaround should be possible, but not straightforward as you will have to make direct calls to GCM, APNS, and the Core SDK to populate metadata. Thank you for finding the flaw in the documentation as that should be fixed. At this time if you want to register with a `userID`, the best approach would be to use the Native SDKs. – joe Oct 02 '16 at 23:28
0

@johan @joe Cordova app can use the IBM Bluemix Push Notification service to send user based push notifications. Please follow the below example using BMSPush to register for Push Notifications.

// initialize BMSCore SDK
BMSClient.initialize("Your Push service region");

// initialize BMSPush SDK
var appGUID = "Your Push service appGUID";
var clientSecret = "Your Push service clientSecret";

// Initialize for normal push notifications
var options = {}
BMSPush.initialize(appGUID,clientSecret,options);

// Initialize for iOS actionable push notifications and custom deviceId
var options ={"categories":{
                      "Category_Name1":[
                        {
                          "IdentifierName":"IdentifierName_1",
                          "actionName":"actionName_1",
                          "IconName":"IconName_1"
                        },
                        {
                          "IdentifierName":"IdentifierName_2",
                          "actionName":"actionName_2",
                          "IconName":"IconName_2"
                        }
                      ]},
                    "deviceId":"mydeviceId"
                  };

BMSPush.initialize(appGUID, clientSecret, options);

var success = function(response) { console.log("Success: " + response); };
var failure = function(response) { console.log("Error: " + response); };



// Register device for push notification without UserId
BMSPush.registerDevice(options, success, failure);

// Register device for push notification with UserId
var options = {"userId": "Your User Id value"};
BMSPush.registerDevice(options, success, failure); 

Please go through the Bluemix Cordova Plugin Push SDK doc link.

pradeep sg
  • 193
  • 1
  • 6