iOS push notifications in Swift with the PushFire SDK
This guide shows how to add iOS push notifications in Swift with the native PushFire SDK. The SDK gets the FCM token through Firebase Messaging, registers the device, identifies the subscriber, manages tags and keeps the notification permission in sync. PushFire is the easiest lifecycle messaging platform for AI agents and vibe coders: push and email lifecycle campaigns, segments and workflows behind one small API.
The SDK needs iOS 16 or later, Swift 6 tools and Swift Package Manager.
Prerequisites
- A PushFire account and project. Create one at console.pushfire.app.
- Firebase credentials uploaded to the PushFire project. See Create your first project.
- A Public key (pf_pk_...) from Developers → API keys for the app. Your backend uses a Secret key (pf_sk_...). See Public and Secret keys.
- A Firebase iOS app for your bundle ID, its GoogleService-Info.plist in the Xcode target, and your APNs key uploaded under Firebase → Project Settings → Cloud Messaging.
- In Signing & Capabilities: Push Notifications, and Background Modes with Remote notifications.
Install the Swift SDK with Swift Package Manager
In Xcode, choose File → Add Package Dependencies and enter:
Choose Up to Next Major Version from 0.1.0 and add the PushFire library. Add PushFireFirebaseAuth or PushFireSupabaseAuth only if you want automatic login from that auth system. Or in Package.swift:
Initialize Firebase and PushFire
The SDK does not call FirebaseApp.configure(). Call it yourself at launch, or registration fails.
Then configure PushFire once. Do all work that touches PushFire.shared after configure returns, in the same task, because shared throws PushFireError.notInitialized until then.
PushFireConfiguration options: apiKey (required), baseURL, enableLogging (development only), timeout (30 seconds), requestNotificationPermission (default true), registerWithoutPrompt and userDefaultsSuiteName (use an app group suite to share state with a Notification Service Extension).
If your app sets FirebaseAppDelegateProxyEnabled to NO, forward the APNs token, or the SDK never gets an FCM token and reports no error:
Register the device and identify the subscriber
configure registers the device and creates an anonymous subscriber. For automatic login, pass an auth provider:
For Supabase, import PushFireSupabaseAuth and pass SupabaseAuthProvider(client: supabase) with your existing SupabaseClient. To log in by hand instead:
externalId is your user ID. Your backend targets it later for batch push and email.
Add, update and remove tags
Create each tag in Audience → Tags and copy its ID. The SDK takes the tag ID (a UUID), not the tag name. A subscriber must be logged in.
Trigger a workflow
Start workflows from your server. Send the ID from try await PushFire.shared.subscriberId() to your backend, then call the REST API there with the Secret key:
Warning: never ship pf_sk_ in a mobile app, browser bundle or no-code frontend. PushFire does not block a Secret key on a client, and anyone can extract it from your app and message all your users. Start workflows and send messages from your server, a Supabase edge function or a Firebase Cloud Function.
The SDK's runWorkflow(_:for:at:) and createWorkflowExecution(_:) are secret key only, not for production apps. With the Public key your app ships, the API answers 403 Client key cannot perform this action. The SDK checks that workflow and target IDs are UUIDs before it sends.
A tag set from the app can also move the subscriber into a segment that starts a workflow, with no server call.
Send push and email from your server
Warning: never ship pf_sk_ in a mobile app, browser bundle or no-code frontend. PushFire does not block a Secret key on a client, and anyone can extract it from your app and message all your users. Start workflows and send messages from your server, a Supabase edge function or a Firebase Cloud Function.
FCM accepts only string values in data, so send numbers and booleans as strings, for example "count": "3".
For email and full server code, see Send push notifications from Node.js or Send push notifications from Python.
Notification permission and status
PushFire tracks two things: the OS permission and the PushFire preference for this device.
The SDK re-checks the OS permission each time the app becomes active. Call syncNotificationPermission() to force it.
Verify delivery
- Run on a physical iPhone. Set enableLogging: true for this test only.
- Watch SDK events:
- Confirm the subscriber, device and tags in Audience → Subscribers.
- Send the batch push and check Developers → API Messages → Push Notifications. The API message history needs the Pro or Enterprise plan.
Troubleshooting
- No device registered, no error: FirebaseApp.configure() was not called, the APNs key is missing in Firebase, or swizzling is off and the APNs token is not forwarded.
- PushFireError.notInitialized: code used PushFire.shared before configure returned, often from a second task. Run it after configure in the same task.
- PushFireError.configuration from runWorkflow: a workflow or target ID is not a UUID.
- 400 "Invalid tag ID": you passed the tag name. Pass the tag UUID.
- 403 "Client key cannot perform this action": a workflow call with the Public key. Move it to your backend.
- No push on the Simulator: test on a device for reliable APNs delivery.
FAQ
Does the PushFire Swift SDK need Firebase?
Yes. PushFire delivers iOS push through Firebase Cloud Messaging, which forwards to APNs. The core PushFire product links only FirebaseMessaging. Firebase Auth and Supabase are separate opt-in products, so you download them only if you want automatic subscriber login from those auth systems.
Can I use the Swift SDK with SwiftUI?
Yes. Add an app delegate with @UIApplicationDelegateAdaptor for FirebaseApp.configure(), and call PushFire.configure in a .task on your root view. Keep every PushFire.shared call after configure in the same task, because shared throws until configuration completes.
Can my iOS app send push notifications to other users?
Not with the Public key it ships. The Public key can register devices, manage the subscriber and set tags. Sending push or email and starting workflows need a Secret key on your server. Your app calls your backend, and the backend calls the PushFire REST API.
How do I set the subscriber timezone from Swift?
The Swift SDK 0.1.0 has no timezone parameter. Set it from your backend with PATCH update-subscriber, sending externalId and an IANA timezone such as America/New_York. Wait nodes set to "At time" then use the subscriber's own timezone.
Next steps
- Build journeys: Workflows and Segments.
- Server calls: Push notification REST API quickstart.
- Keys: API keys.
- All SDKs: PushFire SDKs and libraries.