mitter.io
  • Welcome
  • Migrating from cloud to on-prem
  • Get mitter.io
    • Custom configuration
  • Getting started
    • Build Your First Android App
      • Setup
      • Authenticate a User
      • Start a Basic Chat
      • Selective Deliveries
      • Custom Payloads
    • Build Your First iOS App
      • Overview
      • Installation
      • Basic Setup
      • Receive Push Messages
      • Storyboard
      • Channel List
      • Channel Window
    • Build Your First Web App
      • Setting Up Your App
      • Start a Basic Chat
      • Selective Deliveries
    • Build Your First React Native app
  • Platform Reference
    • Introduction
    • Concepts
    • Authorization and Access
    • Calling the APIs
    • Users
    • Channels
      • Channel Streams and Typing Indicators
    • Messages
    • Delivery Endpoints (Push Notifications)
    • Federated Authentication
    • Basic Permissions and Privileges
    • ACLs and Advanced Permission Model
    • Metadata
  • SDKs
    • Android
      • Getting Started
      • Set up FCM
      • Presence and Timeline Events
      • Profiles, Pagination and Locators
      • Using the UI Framework
    • iOS
      • Installation
      • Basic Setup
      • Get the current user details
      • Create a Channel
      • Messaging
      • Push Messages
    • Javascript
      • Using the UI framework (web only)
      • For react-native
      • For node.js
      • TSDocs / JSDocs
      • For Typescript Users
    • Java (Backend)
Powered by GitBook
On this page
  1. SDKs
  2. iOS

Push Messages

PreviousMessagingNextJavascript

Last updated 6 years ago

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 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.

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.

over here