0

I have already registered my app in Firebase console for my iOS application in Xcode 9, the problem I have is that I can receive the message just when the app is in background or suspend mode , and also can receive it in foreground.

1: I am using

Messaging.messaging().subscribe(toTopic: "/topics/my-topic")

to subscribe to my topic.

and I send it with postman :

{
    "to":"/topics/my-topic",
    "content_available": true,
   "data":
   {
        "message": "some message.."
   }
}

2: I receive the message in the app delegate

 func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        UIApplication.shared.applicationIconBadgeNumber = 0
    }

.

How can I receive the message from the topic and do a local push notification when the app is not running ?

user3678528
  • 1,741
  • 2
  • 18
  • 24
  • When app is not running `userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)` method will be call just use this. – TheTiger May 14 '18 at 09:39
  • should i enable the content-available with the fcm Post ? – mohamed ibrahem May 14 '18 at 09:55
  • I tried to increment the badge number in this method but it doesn't work :( .. how can i register to userNotificationCenter ? – mohamed ibrahem May 14 '18 at 09:58
  • I guess no need, I used `content_available = true` for silent push not for this case. – TheTiger May 14 '18 at 09:58
  • [See this answer](https://stackoverflow.com/a/44142742/1140335) when app is not active. – TheTiger May 14 '18 at 09:59
  • You need to register it in `appDidFinishLaunching:` method and tutorials are available on google. – TheTiger May 14 '18 at 10:00
  • i already registered but doesn't cannot receive the message in func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response:... – mohamed ibrahem May 14 '18 at 11:06
  • Did you tap the notification in notification center ? – TheTiger May 14 '18 at 11:06
  • what you mean to tap the notification ? – mohamed ibrahem May 14 '18 at 11:12
  • App is minimized or kill... Notification came.... Did you click on that notification? How do you suppose how notification will show? – TheTiger May 14 '18 at 11:14
  • i tried to increment the badge number in the method , but id doesn't work ! that's mean the method is didn't receive the message ! – mohamed ibrahem May 14 '18 at 11:19
  • You will have to send the badge number in push notification payload you can not change anything if app is not in running state. See [Apple Doc](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html) for more detail. – TheTiger May 14 '18 at 11:21
  • i don't want to send "notification" : { "body" : "This is a Firebase Cloud Messaging Topic Message!", "title" : "FCM Message" } in the payload , i want to get the remote message even the app is running or not ! and to decide to do push notification or not ! according to the data in the Fcm's payload – mohamed ibrahem May 14 '18 at 11:26
  • I know this is FCM but here too you can send badge. Without sending the badge its not possible. – TheTiger May 14 '18 at 11:29

0 Answers0