Es gibt ein Problem mit iOS und Datennachrichten. Darin heißt es, dass here
Auf iOS-Geräten FCM die Nachricht speichert und liefert es nur, wenn die Anwendung in der Vordergrund und hat eine FCM-Verbindung hergestellt.
Also es muss eine Arbeit geben. Etwas ähnlich wie mir:
Senden 2 Push-Benachrichtigungen:
1) Normale die Benutzer zu wecken Telefon/initiieren, während die App im Hintergrund ist mit diesem Code:
{
"to" : "/topics/yourTopicName",
"notification" : {
"priority" : "Normal",
"body" : "Notification Body like: Hey! There something new in the app!",
"title" : "Your App Title (for example)",
"sound" : "Default",
"icon" : "thisIsOptional"
}
}
2) Datenbenachrichtigung, die ausgelöst wird, wenn Benutzer die App öffnet
{
"to" : "/topics/yourTopicName",
"data" : {
"yourData" : "1",
"someMoreOfYourData" : "This is somehow the only workaround I've come up with."
}
}
und so unter der - (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage
Methode mit Ihren Daten umgehen:
- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
// Print full message
NSLog(@"%@", remoteMessage.appData);
//
//*** ABOUT remoteMessage.appData ***//
// remoteMessage.appData is a Key:Value dictionary
// (data you sent with second/data notification)
// so it's up to you what will it be and how will the
// app respond when it comes to foreground.
}
Ich werde auch diesen Code verlassen die Benachrichtigung innerhalb der App zu triggern (erstellen lokale Benachrichtigung), da Sie es verwenden können, eine erstellen vielleicht zum Schweigen gebracht banner, so dass der Benutzer wieder einmal informiert wird, wenn der App kommt in dem Vordergrund:
NSDictionary *userInfo = remoteMessage.appData;
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.userInfo = userInfo;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.alertBody = userInfo[@"yourBodyKey"];
localNotification.alertTitle = userInfo[@"yourTitleKey"];
localNotification.fireDate = [NSDate date];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Es Benachrichtigung auslösen gleiche Sekunde der App im Vordergrund kommen.
Mögliche Duplikate von [Keine APNs erhalten, wenn sie nicht in der App sind] (http://stackoverflow.com/questions/40295475/not-receiving-apns-when-out-of-app) – Chris
Die Frage, auf die Sie mich verwiesen haben hat keine Antworten und ist anders formuliert. –