我使用Parse.com與Ionic應用程序和PushPlugin並試圖通過GCM與自定義發件人ID實現Parse的推送通知。Parse.com推送通知不顯示在android上的背景
當我向所有設備發送消息或使用帶有cURL的REST API時,iOS通知在應用程序處於後臺時觸發正常,但android通知不適用。
這就是我與其他API第一次嘗試針對iOS,這是正常工作:
curl -X POST \
-H "X-Parse-Application-Id: APP-ID" \
-H "X-Parse-REST-API-Key: API-KEY" \
-H "Content-Type: application/json" \
-d '{
"where": {
"deviceType": "ios"
},
"data": {
"alert": "Hello World!"
}
}' \
https://api.parse.com/1/push
iOS的通知接收即使該應用程序被關閉或開放的背景顯示。
現在,當我嘗試同樣瞄準Android設備:
curl -X POST \
-H "X-Parse-Application-Id: APP-ID" \
-H "X-Parse-REST-API-Key: API-KEY" \
-H "Content-Type: application/json" \
-d '{
"where": {
"deviceType": "android"
},
"data": {
"alert": "Hello World!"
}
}' \
https://api.parse.com/1/push
該通知是由設備接收和adb logcat
部分記錄,但在通知欄或不顯示其它方法確認。我嘗試將'alert'
更改爲'message'
,但這沒有效果。
但是,如果我嘗試使用與郵差或捲曲的GCM HTTP API,一切正常:
curl 'https://android.googleapis.com/gcm/send' \
-H 'authorization: key=API-KEY' \
-H 'content-type: application/json' \
-d '{
"registration_ids" : [
"DEVICE-REGISTRATION-ID"
],
"data" : {
"message": "You Go I Go, Buddy!"
}
}'
當登錄adb logcat
日誌使用GCM API和解析的推送通知API時是不同的:
隨着解析:
I/GCM (10319): GCM message co.yougoigo.mobile 0:1423318254669687%bd9ff524f9fd7ecd
V/GCMBroadcastReceiver(11506): onReceive: com.google.android.c2dm.intent.RECEIVE
V/GCMBroadcastReceiver(11506): GCM IntentService class: com.plugin.gcm.GCMIntentService
V/GCMBaseIntentService(11506): Acquiring wakelock
V/GCMBaseIntentService(11506): Intent service name: GCMIntentService-GCMIntentService-3
D/GCMIntentService(11506): onMessage - context: [email protected]
而且隨着GCM捲曲電話:
I/GCM (10319): GCM message co.yougoigo.mobile 0:1423318321652064%bd9ff524f9fd7ecd
I/ActivityManager( 745): Start proc co.yougoigo.mobile for broadcast co.yougoigo.mobile/com.plugin.gcm.CordovaGCMBroadcastReceiver: pid=11788 uid=10187 gids={50187, 9997, 3003} abi=armeabi-v7a
V/GCMBroadcastReceiver(11788): onReceive: com.google.android.c2dm.intent.RECEIVE
V/GCMRegistrar(11788): Setting the name of retry receiver class to com.plugin.gcm.CordovaGCMBroadcastReceiver
V/GCMBroadcastReceiver(11788): GCM IntentService class: com.plugin.gcm.GCMIntentService
V/GCMBaseIntentService(11788): Acquiring wakelock
V/GCMBaseIntentService(11788): Intent service name: GCMIntentService-GCMIntentService-1
D/GCMIntentService(11788): onMessage - context: [email protected]
E/GCMIntentService(11788): Number format exception - Error parsing Notification ID: Invalid int: "null"
V/GCMBaseIntentService(11788): Releasing wakelock
目前的清單如下:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="4" android:versionName="0.0.4" package="co.yougoigo.mobile" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="CordovaApp" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:exported="true" android:name="com.plugin.gcm.PushHandlerActivity" />
<receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="co.yougoigo.mobile" />
</intent-filter>
</receiver>
<service android:name="com.plugin.gcm.GCMIntentService" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id" />
<activity android:label="@string/fb_app_name" android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="co.yougoigo.mobile.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="co.yougoigo.mobile.permission.C2D_MESSAGE" />
</manifest>
有誰有越來越GCM通知上的PhoneGap應用工作的經驗嗎?
我有完全相同的體驗。這有什麼好運?你如何在解析中設置你的安裝? – 2015-02-17 22:17:25
通知未顯示的原因是因爲Parse會將android通知發送到其他自定義接收器。你必須使用像https://github.com/avivais/phonegap-parse-plugin這樣的東西來包含Parse SDK,但是對於我來說插件會中斷。我最終做的是直接通過GCM發送android推送通知,而不是Parse Push。 – BarakChamo 2015-02-18 10:07:47
這是我的懷疑。我也試圖使用相同的分析插件,但每次打開時都會崩潰。我猜這意味着你沒有爲iOS開發。我正在尋找一個好的混合解決方案。 – 2015-02-18 19:43:49