Push Messages
Before you can start receiving messages through FCM, you need to setup FCM in your project.
Firebase has a pretty comprehensive tutorial for setting up FCM. Follow the steps over here and you should be ready to receive messages via FCM.
Now that you’ve configured FCM in your project you can hook it up with Mitter using the following steps:
Register a delivery endpoint
Before receiving any messages from Mitter you need to register the device’s FCM token as a delivery endpoint with Mitter.
You can get and register the FCM token by calling the registerFcmToken()
function on the Mitter
object within the function which has the signature of didRegisterForRemoteNotificationsWithDeviceToken
variable, like this:
After that, you need to process incoming FCM messages by forwarding them to Mitter. Look for the function called userNotificationCenter()
which has the variable named willPresent
and then get the serialised data dictionary from the FCM notification dictionary, like this:
Next, you need to convert this into a MessagingPipelinePayload
object. This can be done by passing the serialised dictionary from the previous step, like this:
Now that you have the MessagingPipelinePayload
object, you can check if the message is from Mitter by calling the function isMitterMessage()
which returns Bool
.
Next, you need to process the push message by passing the MessagingPipelinePayload
object and hooking up the completion handlers, like this:
Here, payload
is an enum which has various cases like NewMessagePayload
, NewChannelPayload
, etc.
Do note, for FCM messages to work, you need to run the project in a physical iOS device.
Also, you need to include dataType as cloud-notification on any message that choose to send using a direct API call from Postman or any other REST client.
Last updated