Early access · launching soon. Request access

Early access

Early access · launching soon
Product
IntelligenceEarly access. Designed and in development. No results yet. See what's left on the roadmap.
Developers
Resources
Request access

A person reads every request.

SDKsEarly accessDesigned and in development. No results yet. See what's left on the roadmap.

iOS push notifications quickstart (Swift)

Oricato Team Last updated SDK 1.0.1

Early access · launching soon. This guide uses the Oricato iOS SDK 1.0.1, the version in the current SDK kit.

You will add the OricatoPush Swift package to a UIKit or SwiftUI app, pass the Firebase Cloud Messaging (FCM) token to Oricato, let Oricato handle its own notifications in your notification delegate, and send a test push to a real iPhone. An optional last step adds a Notification Service Extension for images and delivery receipts.

The examples use a neutral app called Lingora with the bundle ID com.lingora.app.

How iOS delivery works

Oricato sends iOS notifications through your own Firebase project: Oricato hands the message to FCM (HTTP v1), and FCM forwards it to Apple Push Notification service (APNs). Your app keeps using Firebase Messaging for the push token. The SDK has no third-party dependencies. It registers the installation with Oricato, reports opens, deliveries and conversions, opens launch URLs, and (with the extension) shows images.

The Swift package has two products:

Product Add it to Contains
OricatoPush Your app target Oricato (initialize, FCM token, tags, handlers, permission, delegate helpers)
OricatoPushNotificationService A Notification Service Extension target (optional) OricatoNotificationService, OricatoNotificationServiceHelper

Prerequisites

  • Xcode 15 or newer (Swift 5.9) and an app with an iOS 13+ deployment target.
  • Firebase Messaging in the app: FirebaseCore and FirebaseMessaging from firebase-ios-sdk, with the GoogleService-Info.plist of the same Firebase project you connect to Oricato.
  • An APNs authentication key (.p8) uploaded in Firebase: Firebase console → Project settings → Cloud Messaging → Apple app configuration, with its Key ID and your Team ID. Without it, every iOS send fails with the reason apns_auth_error. See Firebase and APNs credentials. One Apple key can serve several providers, so you can reuse a key you already have.
  • An Oricato project with your Firebase service account key uploaded (a dedicated service account with only the Firebase Cloud Messaging API Admin role, not the default firebase-adminsdk key). The credentials guide above covers this too.
  • Capabilities on the app target (Signing & Capabilities):
    • Push Notifications: required.
    • Background Modes → Remote notifications: turn it on (Firebase recommends it).
    • Time Sensitive Notifications: only if you will send with the time-sensitive interruption level.
    • App Groups: only for the “badge increase” option in step 5.
  • A real iPhone to test on, with a Debug build installed from Xcode.

The two values you need

Value Where you find it Used as
Project ID Dashboard → your project → Settings → Add Oricato to your app. A UUID such as 0192e1aa-1111-7c22-8d33-445566778899. <ORICATO_PROJECT_ID> in the code below
API address Shown on the same screen. Copy it exactly: do not add /api/v1 or a trailing slash. The SDK rejects a query, a fragment or user info and strips trailing slashes. <ORICATO_API_ADDRESS> in the code below

Step 1: Add the Swift package

  1. Copy the ios/OricatoPush folder from the SDK kit into your app’s repository, for example as Packages/OricatoPush next to the .xcodeproj. Xcode stores the path of a local package, so keeping it in the repository lets the app build on any machine.
  2. In Xcode choose File → Add Package Dependencies… → Add Local…, select the OricatoPush folder and click Add Package.
  3. In the product list, add OricatoPush to your app target. Leave OricatoPushNotificationService set to None for now. Step 5 adds it to the extension.

What you should see: OricatoPush listed under Package Dependencies in the project navigator, and import OricatoPush compiling in your app target.

Step 2: Initialize Oricato in your app delegate

Add the Oricato lines to application(_:didFinishLaunchingWithOptions:). This is the complete app delegate. If you already have one, add only the lines that mention Oricato, Messaging and the notification center delegate.

import UIKit
import FirebaseCore
import FirebaseMessaging
import OricatoPush

@main
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        FirebaseApp.configure()
        Messaging.messaging().delegate = self

        Oricato.initialize(projectId: "<ORICATO_PROJECT_ID>", apiBaseURL: "<ORICATO_API_ADDRESS>")

        UNUserNotificationCenter.current().delegate = self
        Oricato.onNotificationOpened { notification in
            // notification.messageId, .title, .body, .launchUrl, .additionalData
        }
        Oricato.requestPermission()  // or later, at a better moment of your onboarding
        application.registerForRemoteNotifications()
        return true
    }
}

What each call does:

  • Oricato.initialize(projectId:apiBaseURL:) is idempotent, so call it at every launch. It creates or loads the subscription ID, saves the settings, starts lifecycle observation and registers the installation. Note the capital URL in apiBaseURL: the old spelling apiBaseUrl is marked unavailable and does not compile.
  • Oricato.onNotificationOpened(_:) receives an OricatoNotification on the main thread whenever someone taps an Oricato notification. Its fields are messageId, title, subtitle, body, launchUrl, imageUrl and additionalData (a [String: String] dictionary). By default the SDK also opens launchUrl once per tap; turn that off with Oricato.setLaunchUrlsAutoOpen(false).
  • Oricato.requestPermission() asks for permission with [.alert, .sound, .badge] and registers for remote notifications when granted. The full signature is requestPermission(options:completion:), and the completion receives a Bool on the main thread. You can ask later in your onboarding instead; see Notification permission.

SwiftUI apps

Keep the class above without @main and connect it from your App:

import SwiftUI

@main
struct OricatoMyApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}

Step 3: Pass the FCM token to Oricato

Firebase calls the MessagingDelegate method at every start and whenever the FCM token changes. Forward the token to Oricato. Add these methods inside the same AppDelegate:

    // Firebase → Oricato: called at every start and whenever the FCM token changes.
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        Oricato.setFCMToken(fcmToken)
    }

    // Only needed when Firebase method swizzling is off (FirebaseAppDelegateProxyEnabled = NO).
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
    }

If you already have a MessagingDelegate, add only Oricato.setFCMToken(fcmToken) to its token method. Passing nil clears the token.

Step 4: Let Oricato handle its notifications first

Add the two UNUserNotificationCenterDelegate methods to the same AppDelegate. Each one calls the Oricato helper first and returns when the helper returns true:

    // MARK: UNUserNotificationCenterDelegate — let Oricato handle its own notifications first.

    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        willPresent notification: UNNotification,
        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
    ) {
        if Oricato.userNotificationCenter(center, willPresent: notification, withCompletionHandler: completionHandler) {
            return
        }
        completionHandler([.banner, .list, .sound])  // your other notifications
    }

    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Void
    ) {
        if Oricato.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler) {
            return
        }
        completionHandler()  // your other notifications
    }

The helpers return false and do nothing for pushes that are not Oricato’s (no fx_id/fx_v keys) or that belong to another Oricato project, so your existing notification handling keeps working. For Oricato notifications they call the completion handler themselves: willPresent reports a foreground delivery and shows the notification, and didReceive reports opened for a tap (the default action), opens the launch URL and calls your onNotificationOpened handler.

No delegate of your own? Skip the two methods and call this instead, after Oricato.initialize(…) and after any other SDK sets its delegate:

Oricato.installNotificationCenterDelegate()

It installs a proxy that handles Oricato notifications and forwards everything else to the delegate that was set before it.

Notes for this step

  • Set the delegate inside didFinishLaunchingWithOptions. That way the tap that launched the app from a cold start reaches Oricato. A tap that arrives before onNotificationOpened is registered is kept (one item, up to 5 minutes old) and handed to the handler as soon as you register it.
  • Swift 6 language mode: declare the conformance as @preconcurrency UNUserNotificationCenterDelegate. This is a UIKit requirement, not an Oricato one.
  • iOS 13 deployment target: [.banner, .list, .sound] needs iOS 14. With an iOS 13 target use [.alert, .sound] for your other notifications.
  • Foreground look: Oricato notifications in the foreground use banner, list, sound and badge by default. Change that with Oricato.setForegroundPresentationOptions(_:), or hide one by returning false from Oricato.onForegroundNotification(_:).
  • Language: the SDK sends the language your app shows (Bundle.main.preferredLocalizations). If you switch languages inside the app, call Oricato.setLanguage("de"); nil follows the app localization again.

Step 5 (optional): Add a Notification Service Extension

Without an extension, Oricato counts opens for every notification but deliveries only for notifications that arrive while the app is in the foreground, and images are not shown. With the extension, every push reports delivered (when the server asks for it) and shows its image. We recommend it.

  1. In Xcode choose File → New → Target… → Notification Service Extension. Name it NotificationService, use the app’s deployment target (iOS 13 or later), and answer Don’t Activate when Xcode asks about the scheme. If your app already has a Notification Service Extension, do not add a second one. Use OricatoNotificationServiceHelper inside the existing extension instead; see Migrate from OneSignal.

  2. Select the new extension target → General → Frameworks and Libraries → + and add OricatoPushNotificationService.

  3. Replace the generated NotificationService.swift with:

    import OricatoPushNotificationService
    
    class NotificationService: OricatoNotificationService {}
  4. In the extension’s Info.plist, add the key OricatoApiBaseURL (String) with your API address, the same value you pass to initialize. Alternatively, override var apiBaseURL: String? in your subclass.

    <key>OricatoApiBaseURL</key>
    <string><ORICATO_API_ADDRESS></string>
  5. In the app, right after Oricato.initialize(…), tell the SDK that the extension reports deliveries, so they are not counted twice:

    Oricato.setDeliveryReportedByExtension(true)

How the extension works: Oricato always sends mutable-content: 1, so iOS runs the extension for every Oricato push. The extension needs no App Group and no shared storage. It reads the project, subscription, message ID and receipt key from the push itself (fx_pid, fx_sid, fx_id, fx_rk). It sends the delivered receipt only when the push contains fx_dr = "1" (this device is in the receipt sample; 8 second timeout, one retry after 1 to 5 seconds), and at the same time downloads fx_image and attaches it. The image download does not depend on the receipt: a missing OricatoApiBaseURL stops only the delivered receipt, not the image. Images must be https, at most 10 MB, and finish downloading within a 15 second budget. If iOS ends the extension’s time early, the text notification is shown. Pushes that are not Oricato’s pass through unchanged; override didReceiveOtherNotification(_:withContentHandler:) to change that.

Badge increase (optional)

The composer’s “badge increase” option (fx_badge_inc) needs a counter shared by the app and the extension:

  1. Add the same App Group, for example group.com.lingora.app, to the app target and the extension target.

  2. In the app, after initialize, call:

    Oricato.setAppGroup("group.com.lingora.app")
  3. In the extension’s Info.plist, add the key OricatoAppGroup (String) = group.com.lingora.app.

Without an App Group the key is ignored. Use the composer’s “set badge” option instead.

Verify it works

  1. Turn on SDK logs while you test, right after initialize:

    Oricato.setLogLevel(.debug)

    Levels are .none, .error, .warn (the default), .info, .debug and .verbose. Open Console.app on your Mac, select the iPhone and filter by the subsystem com.oricato.push.

  2. Run a Debug build on a real iPhone, open the app once and allow notifications.

  3. In the dashboard, open your project → Verify setup. The live checklist shows Firebase key works, then Your app connected (your iPhone’s model appears).

  4. Press Send test notification. It sends “It works!” to this phone only and is not counted in statistics. The checklist ticks arrived when it lands and opened after you tap it.

  5. Tap the notification and check that your onNotificationOpened handler runs (add a print or a breakpoint).

  6. Optional: under Keep this phone for testing, name the phone and press Mark as test device. The composer’s “Try it on your phone first” then sends to your test devices (listed under Audience → Test devices).

To find this installation, print its subscription ID and search for it in Audience:

print("Oricato subscription:", Oricato.subscriptionId)

Troubleshooting

Symptom Likely cause and fix
Sends fail with apns_auth_error No APNs authentication key in Firebase. Upload the .p8 key under Firebase console → Project settings → Cloud Messaging → Apple app configuration. See Firebase and APNs credentials.
Log says “Wrong Project ID” The Project ID or API address passed to initialize is wrong (HTTP 404). The SDK stops all calls until the next launch, so fix the values and relaunch. An archived project (HTTP 410) pauses calls for 24 hours.
initialize logs an error and nothing happens The Project ID must be the project’s UUID, and the API address must be https:// with no query. http:// addresses are accepted only in Debug builds or for localhost (a simulator against a local server). Use https:// in every Release build you ship. The OricatoApiBaseURL in the extension’s Info.plist follows the same rule (http only in the extension’s Debug build or for localhost).
The phone never appears in Verify setup No FCM token reached Oricato. Check that Messaging.messaging().delegate = self runs before the token arrives and that messaging(_:didReceiveRegistrationToken:) calls Oricato.setFCMToken. If swizzling is off (FirebaseAppDelegateProxyEnabled = NO), set Messaging.messaging().apnsToken in didRegisterForRemoteNotificationsWithDeviceToken. Also check the Push Notifications capability. Test on a real iPhone: simulators are not a reliable way to get an APNs-backed FCM token.
Taps on a cold start do not reach your handler The notification center delegate (or installNotificationCenterDelegate()) is set after didFinishLaunchingWithOptions returns. Set it inside that method.
Opened works but delivered stays empty The extension is missing, Oricato.setDeliveryReportedByExtension(true) is set without an extension, or the extension’s Info.plist has no OricatoApiBaseURL. Without an extension, deliveries are counted only in the foreground.
No image The extension is missing, the image URL is not https, the image is larger than 10 MB, or the download did not finish within the 15 second budget.
Badge increase does nothing The app and the extension do not share an App Group, or setAppGroup / OricatoAppGroup is missing on one side.

For Firebase and APNs credential errors, see Firebase and APNs credentials.

SDK reference (1.0.1)

Call What it does
Oricato.initialize(projectId:apiBaseURL:) Idempotent; call at every launch.
Oricato.setFCMToken(_:) The FCM registration token from Firebase Messaging (nil clears it).
Oricato.setLanguage(_:) Language the app shows; nil follows the app localization.
Oricato.setExternalUserId(_:hash:) Your opaque, pseudonymous user ID (never an email address or phone number). nil clears it.
Oricato.setTags(_:) Merges tags such as ["plan": "pro"]; a nil or empty value removes a key. Up to 50 tags.
Oricato.optIn() / Oricato.optOut() App-level switch for receiving pushes (opted in by default).
Oricato.trackEvent(_:) Records a conversion such as completed_onboarding (lowercase letters, digits and _, up to 40 characters).
Oricato.onNotificationOpened(_:) Handler for taps on Oricato notifications (main thread).
Oricato.onForegroundNotification(_:) Handler for Oricato notifications in the foreground; return false to hide one.
Oricato.setForegroundPresentationOptions(_:) How foreground notifications look (default banner, list, sound, badge).
Oricato.subscriptionId / Oricato.getSubscriptionId() This installation’s subscription UUID.
Oricato.requestPermission(options:completion:) Asks for permission and registers for remote notifications when granted.
Oricato.getPermissionStatus(_:) granted, denied, notDetermined or provisional.
Oricato.setLaunchUrlsAutoOpen(_:) Open launchUrl on tap (default true).
Oricato.setAppCheckTokenProvider(_:) Firebase App Check token source.
Oricato.setDeliveryReportedByExtension(_:) true when the extension from step 5 is installed.
Oricato.setAppGroup(_:) App Group for badge increase.
Oricato.setLogLevel(_:) .none, .error, .warn (default), .info, .debug, .verbose.
Oricato.installNotificationCenterDelegate() Automatic notification delegate proxy.
Oricato.isOricatoNotification(_:) true for an Oricato userInfo.

To send messages in each user’s language, see Languages and localized messages.

Next steps

Related

Get early access to Oricato.

Founding teams get early access, free help moving from OneSignal, and a founding discount.

We use this to reply, plan your invitation and set up your account. Privacy Policy

A person reads every request.

Or get the monthly newsletter