如何使用Bluemix在混合移动应用程序中实现推送通知 [英] How to implement Push Notification in Hybrid Mobile Application using Bluemix

查看:80
本文介绍了如何使用Bluemix在混合移动应用程序中实现推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前使用以下代码在混合移动应用程序中实现了推送.

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);
}

现在由于Push服务的更改,我正在实施Push Notification,\

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.

初始化错误->>参考错误:未定义BMSClient.

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

在我的index.html中,我包含了MPUSH.js和BMSClient.js

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

我通过创建cordova项目并为其添加环境来获得这些.js(MFPush.js,BMSClient.js)文件.

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

我浏览了blumix文档,为iOS,Android和Cordova应用程序提供了Push Notification,但对于混合移动应用程序则没有.

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

请在这方面提供帮助!

我没有在混合应用程序中使用适配器来初始化Bluemix SDK.

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

我还检查了以下链接.

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

推荐答案

最终更新

我本来以为该项目在架起科尔多瓦桥时遇到了麻烦,但是,我发现缺少本机依赖项.这是由于MFP不支持Gradle,因此您需要对插件进行一些编辑才能使项目在MFP中运行.

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" />

您需要对添加的每个Bluemix Mobile Services插件执行此操作,直到MFP支持Gradle.

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

这篇关于如何使用Bluemix在混合移动应用程序中实现推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆