2016-01-08 22 views
2

我早先正在使用以下代碼在混合移動應用程序中實施推送。如何在使用Bluemix的混合移動應用程序中實施推送通知

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服務改變,我實現推送通知,\

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

我這些的.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

+0

您正在使用什麼版本的Mobile First Platform Foundation? –

+0

嗨,戴夫!我正在使用MFP版本7。1 – user3719130

回答

1

最後更新

我原本以爲,該項目遇到了麻煩拿起科爾多瓦橋樑,但是,我想通了,本地的依賴失蹤。這是由於MFP不支持Gradle,所以您需要對插件進行一些編輯才能使項目在MFP中運行。

完成下面的每個插件,您希望使用:

  • list of Bluemix MobileFirst maven central repos下載相應的.aar
  • 提取從.aarclasses.jar,並重新命名.jar到該插件可識別的東西(即核心1.1.1.jar)
  • 添加插件到您的項目後,在plugins/<plugin-name>/src/android創建libs文件夾拖放您新.jar更名爲libs目錄。
  • 最後,打開plugin.xml文件,並將構建路徑添加到<platform name="android">目標中的.jar。它應該看起來像這樣<lib-file src="src/android/libs/core-1.1.1.jar" />

您需要爲每個您添加的Bluemix Mobile Services插件執行此操作,直到MFP支持Gradle。

+0

嗨Dave,感謝您的回覆,我試圖按照您的建議實施,但我仍然在ERROR下得到相同的結果。 啓動錯誤 - >> ReferenceError:BMSClient未定義。我在這裏有一個查詢,我是否需要將這些文件CDVMFPPush.java和CDVBMSClient.java添加到libs文件夾或android src文件夾中。 – user3719130

+0

Android src文件夾可能更合適。我在我的指示中將它們視爲罐子(基於舊文檔),所以我認爲你是對的。 我你知道它的工作讓我知道。下週我會有一些時間爲自己嘗試一下。 –

+0

嗨戴夫,我無法找出問題。所以我分享了代碼的鏈接。看到我的推送通知的示例項目代碼後,請檢查並提供建議。 (我創建了移動第一個項目並實施了推送通知)。這裏是相同的鏈接。 https://drive.google.com/file/d/0BzuSOc4RrrpJengwUFVKQ1RsLWc/view?usp=sharing – user3719130

相關問題