2

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

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

现在由于推送服务的变化,我正在实施推送通知,\

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


}

但我收到以下错误。

初始化错误-->>ReferenceError: BMSClient 未定义。

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

我通过创建一个cordova项目并向它们添加环境来获得这些.js(MFPush.js,BMSClient.js)文件。

我浏览了 blumix 文档,推送通知适用于 iOS、Android 和 Cordova 应用程序,但不适用于混合移动应用程序。

请在这方面提供帮助!

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

我还检查了以下链接。

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

4

1 回答 1

0

最终更新

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

为您希望使用的每个插件完成以下操作:

  • .aarBluemix MobileFirst maven 中央存储库列表中下载相应的。
  • classes.jar从 中提取.aar并将 重命名.jar为该插件可识别的名称(即 core-1.1.1.jar)
  • 将插件添加到项目后,创建一个libs文件夹plugins/<plugin-name>/src/android并将新重命名的文件夹.jar放入该libs目录。
  • 最后,打开plugin.xml文件并将构建路径添加到.jar目标<platform name="android">中。它应该看起来像这样<lib-file src="src/android/libs/core-1.1.1.jar" />

在 MFP 支持 Gradle 之前,您需要对添加的每个 Bluemix Mobile Services 插件执行此操作。

于 2016-01-08T19:42:30.510 回答