2015-10-23 69 views
0

我們正在使用MFP 7.0.0.00-20150907-1450並構建針對iOS和Android的混合應用程序。
我們使用"send bulk messages" REST API發送廣播消息。如果在使用IBM MobileFirst Platform 7.0關閉應用程序時收到了onMessage未處理的推送通知

我們在我們的應用中實施了WL.Client.Push.onMessage,只要應用在收到通知時運行,它就會處理該消息。 如果應用程序在通知到達手機時關閉,則消息有效內容似乎無法到達我們的onMessage實現。

此行爲在iOS和Android之間是相同的。

我懷疑我們的onMessage函數被分配與MFP框架試圖將消息傳遞到我們的應用程序之間存在計時問題。
關於如何在應用程序關閉時收到消息時處理消息的一些指示將非常棒!

(下面是我們設置的一些細節。)


我們正在使用的角度和這是我們主要的應用程序模塊:

if (angular.isDefined(window.WL) && angular.isDefined(window.WL.Client.Push)) { 
    window.WL.Client.Push.onMessage = function (props, payload) { 
    console.log('Received push notification in client', JSON.stringify(props), JSON.stringify(payload)); 
    $rootScope.$broadcast('pushNotification', props, payload); 
    }; 
} 

注意到在此之後(「你必須在任何函數之外聲明它「)。在onMessage的文檔中,我已將作業移出到甚至是IIFE之外的JavaScript文件的頂部。這個功能似乎並沒有被調用,當然也沒有記錄和變量仍然是不確定的:

var lastPushMessage; 
function pushMessageRecorder(props, payload) { 
    lastPushMessage = { 
    props: props, 
    payload: payload 
    }; 
    console.log('MFP: push received: ' + JSON.stringify(lastPushMessage, null, 2)); 
} 
WL.Client.Push.onMessage = pushMessageRecorder; 

我們的安全測試(用戶不用登錄,只是與我們的鑰匙打包一個應用程序):

<customSecurityTest name="customTests"> 
    <test realm="wl_antiXSRFRealm" step="1" /> 
    <test realm="wl_authenticityRealm" step="1" /> 
    <test realm="wl_remoteDisableRealm" step="1" /> 
    <test realm="wl_directUpdateRealm" mode="perSession" step="1" /> 
    <test realm="wl_anonymousUserRealm" isInternalUserID="true" step="1" /> 
    <test realm="wl_deviceNoProvisioningRealm" isInternalDeviceID="true" step="2" /> 
</customSecurityTest> 
+0

讓我們簡化問題。沒有角碼是否工作?如果是這樣,那麼這個問題不是關於Worklight,而是關於角度。 –

+0

這是一個關於工作燈的問題,不管使用角度。問題在於:MFP何時嘗試將推送數據傳遞給應用程序,以及實現者必須注意哪些因素,以便及時定義onMessage函數? (我會繼續研究不同的配置,但是如果沒有這個答案,即使我在我的環境中工作,我也不能確定它是否適用於現場的所有設備。) – N2O

+0

onMessage隨時被調用該應用程序啓動(如果有登錄,然後登錄)。 –

回答

0

它看起來像我已經得到它的工作。
(晴。如果應用程序沒有運行,用戶直接通過啓動,然後通知仍然不會在應用程序中顯示刷卡離開通知,或打開應用程序。)

有這需要做兩兩件事:

  1. 分配給WL.Client.Push.onMessage必須做「的任何功能之外」
  2. 它看起來像在native/res/values/strings.xml字符串「APP_NAME」的值被用來定位從應用程序推送服務,並確保消息通過

第二點仍然沒有真正意義的我,但它看起來像在AndroidManifest.xml意向篩選器操作android:name值是用這些值構建:由於app_name

{AndroidManifest.xml:/manifest[@package]}.{res/values/strings.xml:/resources/string[@name="app_name"]}.NOTIFICATION 

用於構建通知限定符,它不能有任何空格,這對於手機上顯示的應用程序的名稱不太好。

我已通過添加另一個變量的strings.xml文件(雖然我可以在AndroidManifest.xml太剛硬編碼名稱周圍的工作,然後使用該變量作爲我的標籤

這裏是什麼工作:

res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="app_name">MyApp</string> 
    <string name="app_label">My App</string> 
    <string name="push_notification_title">My App</string> 
    <!-- ... --> 
</resources> 

AndroidManifest.xml

<?xml version="1.0" encoding="UTF-8"?> 

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.MyProject" android:versionCode="1" android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19"/> 
    <supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="false"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <!-- Push permissions --> 
    <permission android:name="com.MyProject.permission.C2D_MESSAGE" android:protectionLevel="signature"/> 
    <uses-permission android:name="com.MyProject.permission.C2D_MESSAGE"/> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> 
    <uses-permission android:name="android.permission.WAKE_LOCK"/> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/> 
    <uses-permission android:name="android.permission.USE_CREDENTIALS"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <application android:label="@string/app_label" android:icon="@drawable/icon"> 
     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 
     <activity android:name=".MyApp" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN"/> 
       <category android:name="android.intent.category.LAUNCHER"/> 
      </intent-filter> 
      <intent-filter> 
       <action android:name="com.MyProject.MyApp.NOTIFICATION"/> 
       <category android:name="android.intent.category.DEFAULT"/> 
      </intent-filter> 
     </activity> 
     <!-- Preference Activity --> 
     <activity android:name="com.worklight.common.WLSettingActivity" android:label="Worklight Settings"/> 
     <!-- UI Activity for displaying native dialogs --> 
     <activity android:name="com.worklight.wlclient.ui.UIActivity"/> 
     <!-- Push service --> 
     <!-- In order to use the c2dm library, an application must declare a class with the name C2DMReceiver, in its own package, extending com.google.android.c2dm.C2DMBaseReceiver 
      It must also include this section in the manifest, replacing "com.google.android.apps.chrometophone" with its package name. --> 
     <service android:name=".GCMIntentService"/> 
     <service android:name=".ForegroundService"/> 
     <!-- Only google service can send data messages for the app. If permission is not set - any other app can generate it --> 
     <receiver android:name="com.worklight.androidgap.push.WLBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> 
      <!-- Receive the actual message --> 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE"/> 
       <category android:name="com.MyProject"/> 
      </intent-filter> 
      <!-- Receive the registration id --> 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.REGISTRATION"/> 
       <category android:name="com.MyProject"/> 
      </intent-filter> 
     </receiver> 
    </application> 
</manifest> 
相關問題