2015-02-09 65 views
3

我有一個使用Ionic Framework開發的Android應用程序。我正在使用ngCordova plugin for push notifications並使用parse.com發送它們解析推送通知不會出現在Android上的通知托盤上

當應用程序正在運行時收到通知,但當應用程序在後臺時通知未在通知托盤上顯示。我收到類似這樣的內容:

notification = { 
    payload: { 
    data: { 
     alert: "message", 
    } 
    } 
} 

但是,當我通過CGM直接發送它們時,通知確實會出現在通知托盤上。我收到的對象是:

notification = { 
    message: "this appear on notification tray", 
    payload: { 
    message: "this appear on notification tray" 
    } 
} 

Parse有什麼問題嗎?或者我錯過了關於Parse的內容?

+0

嘿,你可以請你分享你的代碼(你使用ngCordova設置Parse推送通知的方式) – 2015-03-27 18:43:04

回答

0

這是一種舊帖子,但我用Xamarin和解析推送通知來解決此問題,但我的解決方案可能適用於您(以及將來可能會看到此問題的其他人)。

收到Parse通知後,我結束廣播本地推送通知。在方法

ParsePush.ParsePushNotificationReceived += PushNotificationReceived; 

然後:

首先分配一個接收器解析通知事件

void PushNotificationReceived (object sender, ParsePushNotificationEventArgs e) 
{ 
    var payload = JObject.Parse (e.StringPayload); // Parse the JSON payload 

    Notification.Builder builder = new Notification.Builder (this); 
    builder.SetContentTitle (payload ["alert"].ToString()); 
    builder.SetContentText (payload ["androidDetail"].ToString()); // Note: this is another field I added to the Parse Notification 
    builder.SetDefaults (NotificationDefaults.Sound | NotificationDefaults.Vibrate); 
    builder.SetSound (RingtoneManager.GetDefaultUri (RingtoneType.Notification)); 
    builder.SetSmallIcon (Resource.Drawable.small_notification_icon); 

    var largeIcon = BitmapFactory.DecodeResource (Resources, Resource.Drawable.large_notification_icon); 
    builder.SetLargeIcon (largeIcon); 

    var notification = builder.Build(); 
    notification.Defaults |= NotificationDefaults.Vibrate; 

    NotificationManager notManager = (NotificationManager)GetSystemService (Context.NotificationService); 

    notManager.Notify (0, notification); 
} 

希望這有助於你和其他人誰碰到這個來了!