Skip to main content

Push Notifications

Firebase configuration

To enable push notifications, set up Firebase Cloud Messaging in your own Firebase project and share the credentials with MeetingLawyers:

  1. Create (or open) your Firebase project at Firebase Console and register your iOS app with its Bundle ID.
  2. In Project settingsCloud Messaging, upload your APNs Authentication Key (.p8) along with your Team ID and Key ID.
  3. Download the GoogleService-Info.plist and add it to your Xcode project. See the Firebase Apple platforms setup guide for adding the Firebase SDK via Swift Package Manager.
  4. In Project settingsService accounts, click Generate new private key and send the downloaded JSON file to support@meetinglawyers.com (treat it as a credential — keep it out of source control and send it via secure email, e.g. as a password-protected archive).

Firebase Service Accounts

See: Firebase Documentation

Sample: Our example with push notification

Push notifications

Once the service account is configured, implement push notification handling in your app. Add the following to your AppDelegate.swift:

AppDelegate.swift
@main
class AppDelegate: UIResponder, UIApplicationDelegate {

// Create a class to delegate all push configuration
private let pushNotificationSample = PushNotificationSample()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
pushNotificationSample.configurePush(application: application)
return true
}
}

Create a dedicated class to handle push configuration:

PushNotificationSample.swift
import FirebaseMessaging
import MeetingLawyers
import UIKit
import FirebaseCore
import Foundation

class PushNotificationSample: NSObject {

public func configurePush(application: UIApplication) {

// Enable firebase push notification
registerFirebasePushNotification()

// Enable Push notification
registerForPushNotifications(application: application)

}
}
PushNotificationSample.swift
extension PushNotificationSample {
internal func registerFirebasePushNotification() {
FirebaseApp.configure()
Messaging.messaging().delegate = self
}

internal func registerForPushNotifications(application: UIApplication) {
UNUserNotificationCenter.current().delegate = self

let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { _, _ in }
)
application.registerForRemoteNotifications()

}
}

Receive push token:

PushNotificationSample.swift
// MARK: Firebase Implementation
extension PushNotificationSample: MessagingDelegate {

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
if let fcmToken = fcmToken {
Task {
print("[ApplicationDelegate] Firebase registration token: \(fcmToken)")
do {
try await MeetingLawyersApp.setFirebaseMessagingToken(token: fcmToken)
print("[ApplicationDelegate] Token registered correctly")
} catch {
print("[ApplicationDelegate] Error registering token: \(error)")
}

}
}
}
}

Pass incoming notifications to the SDK:

PushNotificationSample.swift

// MARK: Push notification Implementation
extension PushNotificationSample: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ userNotificationCenter: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
guard MeetingLawyersApp.isMeetingLawyersPush(notification: notification) else {
// Not a MeetingLawyers push — handle it with your own logic
return
}
_ = MeetingLawyersApp.userNotificationCenter(willPresent: notification.request, completionHandler: completionHandler)
}

func userNotificationCenter(_ userNotificationCenter: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
guard MeetingLawyersApp.isMeetingLawyersPush(notification: response.notification) else {
// Not a MeetingLawyers push — handle it with your own logic
completionHandler()
return
}
_ = MeetingLawyersApp.userNotificationCenter(didReceive: response.notification.request) { error in
print("ERROR \(error.debugDescription)")
completionHandler()
}
}
}

Handle didReceive error

If there is any error using func userNotificationCenter(_ userNotificationCenter: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) should be handled and the result redirected.

Top ViewController

The SDK can handle the notification only if the top view controller is an instance of ProfessionalListViewController, MessagesViewController, or ProfileViewController. If the top view controller is not from the SDK (for example, it is one from your application), the method will return a MeetingLawyersError error.

The error can have one of these values:

  • actionFailed(reason: ActionFailureReason)
  • pushesFailed(reason: PushesFailureReason)

And if the value is actionFailed case, the reason values of this error are one of the following, which can be used in the execute function:

  • executionError(pendingAction: MeetingLawyersAction)

The variable of type MeetingLawyersAction should be saved until an instance of the SDK is rendered as the Top ViewController. At this moment, you can call the method func execute(action: MeetingLawyersAction, origin: UIViewController?, completionHandler: @escaping (MeetingLawyersError?) -> Void) to continue with the navigation.

// Handle error
if case let .actionFailed(reason) = error,
case let .executionError(action) = reason {
// Save action to execute later
}

completionHandler()
caution
  • It is necessary that the host application has the necessary permissions and entitlements to receive push notifications.

  • It is essential to provide an Authorization key to the administrator of your MeetingLawyer account so that notifications are received correctly.

  • It is highly recommended to implement background fetch result and modify your app capabilities to include 'fetch' and 'remote-notification' entitlements.

<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>

Next steps