How to implement Push Notification in Hybrid Mobile Application using Bluemix

余生颓废 提交于 2019-12-07 20:35:25

问题


I was earlier implementing push in my hybrid mobile application using the below code.

function EnablePushNotification(email)
{   

    var config = {

            applicationId:'',
            applicationRoute:'',
            applicationSecret:''
            //applicationSecret:''

    };
    console.log("EnablePushNotification : " + email);
    return IBMBluemix.initialize(config)
    .then(function() {
            return IBMPush.initializeService();
    })
    .then(function(push1) {
        var push = IBMPush.getService();
        //device.model
        //userName
        push.registerDevice(email, email, "alertNotification")
            .done(function(response) {
                navigator.notification.alert("Device Registered : " + response);  
                console.log("Device Registered : " + response);
                push.subscribeTag("SmarterSAM-Test").done(function(response) {
                navigator.notification.alert("Device Subscribed : " + response);
                console.log("Device Subscribed : " + response); 
            }, function(err){
                navigator.notification.alert("Error in subscribe : " + err);
                console.log("Error in subscribe : " + err); 
            });
        }, function(err){
            navigator.notification.alert("Error in Registering Device : " + err);
            //console.log("Error in subscribe : " + err);
        });
   });

}

function alertNotification(message)
{
    IBMBluemix.getLogger().info("Received notification");
    navigator.notification.alert("Received notification : " + message);
}

Now due to change in Push service, i am implementing the Push Notification, \

function EnablePushNotification(email)
{
    //deviceUserID = email;
    console.log("--Inside EnablePushNotification--");



    try {
        //initialize SDK with IBM Bluemix application ID and route
        //TODO: Please replace <APPLICATION_ROUTE> with a valid ApplicationRoute and <APPLICATION_ID> with a valid ApplicationId        
        debugger;
        BMSClient.initialize("<APPLICATION_ROUTE>","<APPLICATION_ID>");



        var success = function(message) { console.log("Success: " + message); };
        var failure = function(message) { console.log("Error: " + message); };
        MFPPush.registerDevice({}, success, failure);

        this.registerNotificationsCallback();
    }

    catch (MalformedURLException) {
        console.log("Error in initilization-->>" + MalformedURLException);        
    }


}

But i am getting the below ERROR.

Error in initilization-->>ReferenceError: BMSClient is not defined.

In my index.html, i have included MPUSH.js and BMSClient.js

i got these .js (MFPush.js,BMSClient.js) files by creating a cordova project and adding environment to them.

I have gone through the blumix docs, Push Notification is given for iOS , Android and Cordova applications but not for hybrid mobile app.

Please help in this regard !!

I am not using adapters in my hybrid application to initialize the Bluemix SDK.

I also checked the below link.

https://developer.ibm.com/answers/questions/242476/bluemix-push-service-error-while-registering-devic.html


回答1:


Final Update

I originally thought that the project was having trouble picking up the cordova bridge, however, I figured out that the native dependencies are missing. This is due to MFP not supporting Gradle, so you will need to make some edits to the plugins to get the project working in MFP.

Complete the following for each plugin you desire to use:

  • Download the appropriate .aar from the list of Bluemix MobileFirst maven central repos.
  • Extract the classes.jar from the .aar and rename the .jar to something identifiable to that plugin (i.e. core-1.1.1.jar)
  • After adding the plugin to your project, create a libs folder at plugins/<plugin-name>/src/android and drop your newly renamed .jar into that libs directory.
  • Lastly, open the plugin.xml file and add the build path to the .jar within the <platform name="android"> target. It should look something like this <lib-file src="src/android/libs/core-1.1.1.jar" />

You will need to do this for each Bluemix Mobile Services plugin that you add until MFP supports Gradle.



来源:https://stackoverflow.com/questions/34672269/how-to-implement-push-notification-in-hybrid-mobile-application-using-bluemix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!