> For the complete documentation index, see [llms.txt](https://docs.mitter.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mitter.io/sdks/ios/push-messages.md).

# 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](https://firebase.google.com/docs/cloud-messaging/ios/client) 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:

```
InstanceID.instanceID().instanceID { (result, error) in
            if let error = error {
                print("Error fetching remote instange ID: \(error)")
            } else if let result = result {
                print("Remote instance ID token: \(result.token)")

                self.mitter.registerFcmToken(token: result.token) {
                    result in
                    switch result {
                    case .success(let deliveryEndpoint):
                        print("Endpoint is: \(deliveryEndpoint.serializedEndpoint)")
                    case .error:
                        print("Unable to register endpoint!")
                    }
                }
            }
        }
```

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:

```
let messageString = userInfo["data"] as! String
```

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:

```
let messagingPipelinePayload = mitter.parseFcmMessage(data: messageString)
```

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:

```
if mitter.isMitterMessage(messagingPipelinePayload) {
            let payload = mitter.processPushMessage(messagingPipelinePayload!)

            switch payload {
            case .NewMessagePayload(let message, let channelId):
                print("Received Message: \(message), for Channel: \(channelId)")
            default:
                print("Nothing to print!")
            }
        }
```

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.

&#x20;*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.*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mitter.io/sdks/ios/push-messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
