Overview
The same NottiSDK package that serves iOS also builds for macOS, from version 0.3.0. It keeps the same two products, NottiSDK for the app and NottiSDKExtension for a Notification Service Extension, and the same API: device registration, user identity, tags, engagement events (received / opened / clicked) and rich media. This page covers only what is specific to a Mac. For Notti.initialize, identity, tags and events, follow the iOS page; the calls are the same.
A Mac registers as its own platform (macos), not as a flavour of iOS. It has its own APNs credential in Notti, and a segment or a send can target it.
Not yet verified on a real Mac
The macOS build, the unit tests and the guards pass on macOS in CI, but the SDK has not been run on a real Mac with a signed app and a real push yet. Delegate callbacks, the cold-start click, the session end at quit, the SwiftUI adaptor, rich media and the privacy report are pending the macOS items of the SDK's device checklist. Treat macOS as unverified on hardware and test your build with a real push before shipping it.
Requirements
- macOS 12.0 or later. Mac Catalyst is not supported: a Catalyst app takes the iOS path and reports
platform: "ios". - Xcode 15.3 or later (the same as iOS).
- A Notti backend of v0.32.0 or later, the first release that accepts
platform: "macos". An older backend rejects a Mac registration with an error and the SDK retries on its normal schedule. - An Apple Developer account and an APNs key or certificate for the Mac app.
- A Notti App and its app id and client key (see Get Started with Notti).
Installation
Use the same package as iOS, version 0.3.0 or later.
Swift Package Manager
In Xcode: File → Add Package Dependencies… and enter:
https://github.com/zeeplabs/zeep-notti-ios-sdk.gitUse the dependency rule Up to Next Minor Version from 0.3.0, since before 1.0 a minor release can break the API. Add the NottiSDK product to the Mac app target and, for rich media, NottiSDKExtension to a Notification Service Extension target.
CocoaPods
platform :osx, '12.0'
target 'YourMacApp' do
pod 'NottiSDK', '~> 0.3.0'
end
target 'YourNotificationServiceExtension' do
pod 'NottiSDKExtension', '~> 0.3.0'
endThen run pod install and open the .xcworkspace.
Set up the macOS credential in Notti
A Mac app has its own APNs credential, separate from the iOS one. In the dashboard, open Settings > Push & In-App > Apple macOS, or call POST /v1/apps/{app_id}/credentials/macos-apns, and give the macOS app's bundle ID. Notti sends it to Apple as the push topic.
- The bundle ID must match the Mac app. A wrong bundle ID makes Apple answer
DeviceTokenNotForTopic, and Notti unsubscribes every macOS device of the App until each app registers again. The dashboard asks you to confirm before it replaces a saved credential. - The APNs environment is shared with iOS (
sandboxorproduction). The macOS route has noenvironmentfield. - Until the credential is saved, a registered Mac stays in the App but its pushes fail with
provider_not_configured.
The details and the failure reasons are in Troubleshooting.
Capabilities
In the Mac app target, under Signing & Capabilities:
- Push Notifications, which adds the
com.apple.developer.aps-environmententitlement. A Developer ID or App Store build also needs a provisioning profile that carries it. Without itregisterForRemoteNotificationsnever answers or fails; the SDK logs the error and does not crash. - For a sandboxed app, Outgoing Connections (Client) (
com.apple.security.app-sandboxtogether withcom.apple.security.network.client).
The SDK needs no other entitlement.
Delegate integration
By default the SDK observes the macOS delegates, the same opt-out as iOS: the NSApplicationDelegate callbacks application(_:didRegisterForRemoteNotificationsWithDeviceToken:), application(_:didFailToRegisterForRemoteNotificationsWithError:) and application(_:didReceiveRemoteNotification:), and the delegate of UNUserNotificationCenter. It adds a callback your delegate lacks.
With NottiDisableSwizzling set to true in Info.plist, forward the calls yourself:
final class ForwardingAppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
UNUserNotificationCenter.current().delegate = self
}
func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Notti.Notifications.didRegisterForRemoteNotifications(deviceToken: deviceToken)
}
func application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
Notti.Notifications.didFailToRegisterForRemoteNotifications(error: error)
}
// The macOS call returns nothing: there is no fetch completion handler.
func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String: Any]) {
Notti.Notifications.didReceiveRemoteNotification(userInfo)
}
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
completionHandler(Notti.Notifications.willPresent(notification))
}
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
Notti.Notifications.didReceive(response)
completionHandler()
}
}This is the one API difference between the platforms: didReceiveRemoteNotification returns UIBackgroundFetchResult on iOS and nothing on macOS. A SwiftUI app with @NSApplicationDelegateAdaptor is expected to behave like the iOS adaptor case, which is also pending a run on a real Mac.
What differs from iOS
- Sessions. A session starts when the app becomes active and ends when it resigns active, so switching apps with Cmd-Tab produces several short sessions where iOS produces one. When the user quits while the app is active, the SDK waits up to 1.5 seconds to send the session report; if it does not finish, the local counters are kept and sent with the next session. A force quit, a crash or a power loss loses that session's telemetry, as on iOS.
- In-App Messages are not shown. The API (
trackEvent,Notti.InAppMessages.addClickListener,Notti.Options(opensInAppURLs:)) compiles on a Mac and does nothing: no message is fetched or shown, no In-App request is made, and the SDK opens no URL. The Notti backend never serves In-App to macOS either. - Rich media.
NottiSDKExtensionis the same Notification Service Extension, and is extension-safe on macOS. Add it to a Notification Service Extension target of the Mac app.
Sent to the Notti backend
The same fields as iOS, with these values on a Mac:
| Field | Value on macOS |
|---|---|
platform | macos |
sdk_name | macos (a wrapper still overrides it) |
device_model | The hardware identifier from sysctl hw.model, for example Mac14,9. Never a serial number or hardware UUID, and left out when it cannot be read |
device_os | The macOS version |
The SDK collects no new type of data on macOS. See the iOS privacy section for the full list of what is sent and stored.
Billing and audiences
- A broadcast with no platform filter also reaches macOS devices once they register. Review your campaigns' audience filters before shipping a Mac build.
- Monthly active devices (MAU) count every platform, so a Mac counts like any other device and can bring an App closer to its plan limit.
Known limitations
- Not yet run on a real Mac with a signed app and a real push (see the warning at the top).
- Mac Catalyst is not supported.
- In-App Messages are not shown on macOS.
- Cmd-Tab produces many short sessions.
Source and changelog
The source, the Mac example app (Example/project-mac.yml) and the changelog are in the zeep-notti-ios-sdk repository.