Today we’re releasing v1.0 of our mobile client SDKs, making it simple to power rich in- and out-of-app mobile notification experiences with Knock.

Our mobile SDKs wrap Knock’s client APIs and provide powerful abstractions for setting up push notifications and building in-app notification experiences. They are available now as native libraries across iOS and Android and for multi-platform applications built with Flutter and React Native.

It’s never been easy to ship notifications in your mobile application.

What’s included in our mobile SDKs

Our mobile SDKs provide a complete set of methods for interacting with the Knock client API across iOS, Android, React Native, and Flutter applications. Our SDKs also have methods that automatically handle authentication, token registration/deregistration, tracking engagement metrics (like deep-link clicks), and more.

Here’s what’s included in this release.

Push notifications handled for you

We’ve made it easy to handle push notification integration into your application. We’ve done the schlep work for you: setup is as simple as adding a few lines of code.

Here’s an example of how easy it is to handle device token registration using our iOS SDK’s KnockAppDelegate:

import Knock

class AppDelegate: KnockAppDelegate {
    override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        Task {
            try? await Knock.shared.setup(publishableKey: "your-publishableKey", pushChannelId: "your-apns-channel-id")
        }
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }

    override func pushNotificationTapped(userInfo: [AnyHashable : Any]) {
        // Handle notification tap
    }

    override func pushNotificationDeliveredInForeground(notification: UNNotification) -> UNNotificationPresentationOptions {
        // Handle notification delivery
    }

}

Behind the scenes, our SDKs fetch device tokens, register them against the authenticated user in Knock, and implement handlers to track notification engagement automatically.

Once your device tokens are registered to Knock, you only need to reference your users by their ids to send them push notifications powered by APNS, FCM, or Expo. Knock takes care of the token management and routing for you.

If you prefer to do this more manually and not rely on our automated setup, you can use pre-built methods for fetching the device token and syncing it to Knock directly.

Easily ship real-time in-app notifications

Our SDKs also enable you to easily integrate in-app notification feeds and inboxes to your application, powered by Knock’s in-app infrastructure. Each SDK provides methods for retrieving in-app messages and managing their engagement status (seen, read, or archived). Additionally, we provide methods to connect to Knock’s real-time service for live notification support. You can read more about our in-app infrastructure here.

var feed: Knock.Feed = Knock.Feed()

func initializeFeed() async {
    do {
        guard let userFeed = try await Knock.shared.feedManager?.getUserFeedContent() else { return }
        await MainActor.run {
            self.feed = userFeed
            self.feed.page_info.before = feed.entries.first?.__cursor
        }

        Knock.shared.feedManager?.connectToFeed()

        Knock.shared.feedManager?.on(eventName: "new-message") { [weak self] _ in
            let options = Knock.FeedClientOptions(before: self?.feed.page_info.before)
            Knock.shared.feedManager?.getUserFeedContent(options: options) { result in
                DispatchQueue.main.async {
                    switch result {
                    case .success(let feed):
                        self.feed.entries.insert(contentsOf: feed.entries, at: 0)
                        self.feed.page_info.before = feed.entries.first?.__cursor
                    case .failure(let error):
                        // Handle error here
                    }
                }
            }
        }
    } catch {
        // Handle error here
    }
}

In future releases, we’ll add pre-built UI elements to make getting up and running with our in-app notifications even easier. Stay tuned.

Manage notification preferences within your app

We provide a full set of methods for working with user preferences, making it easy to build notification settings within your application, powered by Knock. You can use Knock’s get preferences and set preferences APIs directly from the app, making the integration even easier.

func getCurrentPreferences() async {
    do {
        let preferenceSet: Knock.PreferenceSet = try await Knock.shared.getUserPreferences(preferenceId: "default")
    } catch {
        // Handle error here
    }
}


func saveCurrentPreferences() async {
    do {
        let updatedPreferenceSet: Knock.PreferenceSet = try await Knock.shared.setUserPreferences(preferenceId: "default", preferenceSet: preferenceSet)
    } catch {
        // Handle error here
    }
}

Powering cross-channel notifications with Knock

Outside of mobile, Knock also supports sending notifications to channels such as email, SMS, and Slack.

You use our dashboard and APIs to manage your notification templates and design workflows that control the logic around where and how a user should receive a notification. Additionally, Knock takes care of:

  • Managing delivery of messages to downstream providers like APNS and FCM
  • Device token management
  • Storing and automatically applying notification settings
  • Localization (i18n) for your notifications
  • Recurring notifications like reminders and digests
  • … and much more

Get started today

Our mobile client SDKs are available today to all Knock customers. You can start integrating by reading our documentation, where you’ll find information about setting up push notifications and using the SDKs to build in-app notification feeds. Get started with a free Knock account, which gives you 10,000 notifications sent for free per month.