Documentation menu

Push notifications setup

Push uses Firebase Cloud Messaging (FCM) on both Android and iOS. Each buyer needs their own Firebase project. Until it's configured, the app builds and runs normally with push off. In-app notifications (the bell) and emails still work.

There are two halves:

  1. API (sending): a Firebase service account, pasted in the admin panel. See firebase.md.
  2. App (receiving): the Firebase config files and, for iOS, an APNs key. This page.

1. Firebase project and apps

  1. In the Firebase console, create a project (Analytics is optional).
  2. Add an Android app for each flavor you ship:
    • prod: your application id, e.g. com.yourcompany.app
    • dev: the same id plus .dev, e.g. com.yourcompany.app.dev
  3. Add an iOS app with your bundle id (plus a .dev one if you use the dev scheme).

Easiest: flutterfire configure

dart pub global activate flutterfire_cli
cd mobile
flutterfire configure --project=<your-firebase-project-id> --platforms=android,ios

It registers the apps and downloads the config files. The app reads the native files, so you can delete the generated lib/firebase_options.dart. It's in .gitignore anyway.

Or place the files by hand

File Where
google-services.json (one app) mobile/android/app/google-services.json
google-services.json (per flavor) mobile/android/app/src/dev/ and mobile/android/app/src/prod/
GoogleService-Info.plist mobile/ios/Runner/GoogleService-Info.plist, added to the Runner target in Xcode

These files are in .gitignore. Don't commit them to a public repository. The Android build applies the Google Services plugin only when one of the google-services.json files exists.

2. iOS: APNs key

FCM delivers to iPhones through Apple Push Notification service.

  1. Go to Apple Developer → Keys → +. Enable Apple Push Notifications service (APNs) and download the .p8 file (you can download it only once).
  2. In Firebase, go to Project settings → Cloud Messaging → Apple app configuration and upload the .p8 file with its Key ID and your Team ID. One key works for development and production.
  3. In Xcode, select the Runner target → Signing & Capabilities, then add Push Notifications and Background Modes with Remote notifications ticked.

Push doesn't work on the iOS Simulator for real FCM delivery. Use a device.

3. What the app does

  • Permission: the app doesn't ask at launch. After the first booking or job post, it shows a short "Get updates on your phone" card. Turn on opens the system prompt (Android 13+ and iOS). Not now hides the card for good. Users can still enable notifications later in system settings.
  • Device registration: after sign-in, on every customer/provider mode switch, and whenever FCM rotates the token, the app sends POST /api/v1/devices (token, platform, app_mode). On logout it calls DELETE /api/v1/devices/{token} and then deletes the FCM token, so that phone stops getting the account's pushes even if it was offline.
  • Android channels: Bookings, Jobs and quotes, Messages and Account and news, named in the phone's language. The API picks the channel from the notification's group, and users can mute each one in system settings.
  • While the app is open: Android shows a heads-up and iOS shows the system banner. There's no banner if the user is already on the screen the push links to (e.g. that chat).
  • Tapping a push opens data.link from every state (open, background, closed), the same way a tap in the in-app list does:
    • If the app was closed, the link opens once the splash screen is done.
    • A /provider/... link switches the app to provider mode first, and a customer link switches back.
    • If the user is signed out, they sign in first and then land on the link.
  • Live refresh: a push about a booking reloads that booking and the bookings list. A new quote reloads that job's quotes. The bell count updates.
  • iOS badge: every push carries the user's unread notification count as the app icon badge.

4. Test it

  1. Set up the API side (firebase.md), then run php artisan queue:work.
  2. Build the app with the config files in place and sign in on a real phone.
  3. Check that the device_tokens table has a row for the user with the right app_mode.
  4. Trigger a notification. Book a service as one user, and the provider gets New booking request. Or send a broadcast with POST /api/v1/admin/notifications/broadcast.
  5. Try all three states: app open, app in the background, and app swiped away. Each tap should open the right screen.
  6. Log out. The device row should disappear, and new notifications for that account shouldn't reach the phone.

Troubleshooting

Symptom Check
Log says Push off: Firebase is not configured Config file missing or in the wrong folder, or the package/bundle id doesn't match the Firebase app
Android gets nothing Notification permission granted? Did the app call POST devices (look in the API log)? Is the service account set in Admin? Is a queue worker running?
iOS gets nothing APNs key uploaded? Push Notifications capability added? Real device?
Wrong side gets the push app_mode in device_tokens. Provider pushes go only to provider-mode devices