Có một vấn đề với iOS và thông điệp dữ liệu. Nó khẳng định rằng here
Trên iOS, FCM lưu trữ thông điệp và cung cấp nó chỉ khi ứng dụng trong foreground và đã thiết lập một kết nối FCM.
Vì vậy, PHẢI có công việc xung quanh. Một cái gì đó tương tự như tôi:
Gửi 2 push thông báo:
1) Bình thường để đánh thức những người sử dụng điện thoại/khởi trong khi ứng dụng là trong nền sử dụng mã này:
{
"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) Thông báo dữ liệu sẽ kích hoạt khi người dùng mở ứng dụng
{
"to" : "/topics/yourTopicName",
"data" : {
"yourData" : "1",
"someMoreOfYourData" : "This is somehow the only workaround I've come up with."
}
}
và, vì vậy, theo phương pháp - (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage
xử lý dữ liệu của bạn:
- (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.
}
tôi cũng sẽ để lại đoạn mã này để kích hoạt các thông báo bên trong ứng dụng (tạo thông báo địa phương), vì bạn có thể sử dụng nó để tạo ra một biểu ngữ im lặng, có thể, do đó, người dùng được thông báo lại ngay cả khi ứng dụng đến tiền cảnh:
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];
Nó sẽ kích hoạt thông báo tương tự ứng dụng thứ hai xuất hiện ở tiền cảnh.
Bản sao có thể có của [Không nhận được APN khi không tham gia ứng dụng] (http://stackoverflow.com/questions/40295475/not-receiving-apns-when-out-of-app) – Chris
Câu hỏi mà bạn đã giới thiệu tôi đến không có câu trả lời và được diễn đạt khác nhau. –