2014-10-28 11 views
13

La mia applicazione riceve notifiche push quando l'applicazione viene chiusa. Ma quando l'app è in esecuzione, non ottengo nulla. Questo è lo stesso codice che ho usato nelle app precedenti senza alcun problema, quelli erano su WindowsPhone8 e le nuove app sono in esecuzione su dispositivi WindowsPhone8.1.PUSH non mostra quando l'app è aperta

Ho utilizzato questo Push Tutorial quando ho creato l'app originale. Ho la riga che dice aggiungi questo se vuoi ricevere le notifiche mentre l'app è aperta.

Se l'aggiornamento 8.1 ha fatto qualcosa per le notifiche push che sarebbe bene sapere. Anche qualcos'altro sarebbe apprezzato.

HttpNotificationChannel pushChannel; 
string channelName = "PushChannel"; 
pushChannel = HttpNotificationChannel.Find(channelName); 
//Push Notifications 
if (pushChannel == null) 

{ 
    pushChannel = new HttpNotificationChannel(channelName); 

    //// Register for all the events before attempting to open the channel. 
    pushChannel.ChannelUriUpdated += 
     new EventHandler<NotificationChannelUriEventArgs>(
     PushChannel_ChannelUriUpdated); 
    pushChannel.ErrorOccurred += 
     new EventHandler<NotificationChannelErrorEventArgs>(
     PushChannel_ErrorOccurred); 

    // Register for this notification only if you need to receive 
    // the notifications while your application is running. 
    pushChannel.ShellToastNotificationReceived += 
     new EventHandler<NotificationEventArgs>(
     PushChannel_ShellToastNotificationReceived); 

    pushChannel.Open(); 

    // Bind this new channel for toast events. 
    pushChannel.BindToShellToast(); 

} 
else... 



void PushChannel_ShellToastNotificationReceived(object sender, 
                 NotificationEventArgs e) 

{ 
    string relativeUri = string.Empty; 

    // Parse out the information that was part of the message. 
    foreach (string key in e.Collection.Keys) 

    { 
     if (string.Compare(
     key, 
     "wp:Param", 
     System.Globalization.CultureInfo.InvariantCulture, 
     System.Globalization.CompareOptions.IgnoreCase) == 0) 

     { 
      relativeUri = e.Collection[key]; 
     } 


    } 
} 
+0

Mostrare un po 'di codice. Stai usando MPNS o WNS? – Fred

+0

Aggiunto il codice. Il resto passa semplicemente aggiungendo i gestori di eventi al PushChannel già esistente. – Seige

+0

In breve, ShellToastNotificationReceived non viene attivato. Non è vero? – fillobotto

risposta

2

Rob Caplan:

brindisi non sono attesi da visualizzare quando l'applicazione è in primo piano. L'app dovrebbe mostrare la propria interfaccia utente, se necessario (lo snippet non mostra nulla). Questo è l'evento ShellToastNotificationReceived: si attiva quando arriva una notifica di brindisi invece del brindisi visualizzato. Puoi confermare che ShellToastNotificationReceived non viene sollevato quando ti aspetti il ​​brindisi? Dovrebbe essere. Puoi confermare che è registrato e ricevuto (o meno) nel debugger? Vedere msdn.microsoft.com/en-us/library/windows/apps/...

Me:

prima che l'aggiornamento 8.1, quando un app aperta ha ricevuto una spinta, il brindisi sarebbe ancora mostrare. Ho appena effettuato alcuni test e, in effetti, l'evento "PushChannel_ShellToastNotificationReceived" è ancora in fase di attivazione, ma il brindisi non viene visualizzato. Immagino che questo significhi solo che devo gestirlo in modo diverso. Se vuoi trasformarlo in una risposta, posso assegnargli la taglia.