iOS SDK API reference
In this section, you'll find the documentation for the classes and methods available in the iOS SDK.
Knock
The top-level Knock class. This is a shared instance to interact with the SDK's API methods.
Knock.shared.setup()
Sets up the shared Knock instance. Make sure to call this as soon as you can. Preferably in your AppDelegate.
Params
KnockAppDelegate
This class serves as an optional base class designed to streamline the integration of Knock into your application. By inheriting from KnockAppDelegate in your AppDelegate, you gain automatic handling of Push Notification registration and device token management, simplifying the initial setup process for Knock's functionalities.
The class also provides a set of open helper functions that are intended to facilitate the handling of different Push Notification events such as delivery in the foreground, taps, and dismissals. These helper methods offer a straightforward approach to customizing your app's response to notifications, ensuring that you can tailor the behavior to fit your specific needs.
Override any of the provided methods to achieve further customization, allowing you to control how your application processes and reacts to Push Notifications. Additionally, by leveraging this class, you ensure that your app adheres to best practices for managing device tokens and interacting with the notification system on iOS, enhancing the overall reliability and user experience of your app's notification features.
Key Features:
- Automatic registration for remote notifications, ensuring your app is promptly set up to receive and handle Push Notifications.
- Simplified device token management, with automatic storage of the device token, facilitating easier access and use in Push Notification payloads.
- Customizable notification handling through open helper functions, allowing for bespoke responses to notification events such as foreground delivery, user taps, and dismissal actions.
- Automatic message status updates, based on Push Notification interaction.
KnockInAppFeedViewModel
KnockInAppFeedViewModel
manages the state and behavior of the in-app feed. It handles data fetching, user actions, state updates, and feed configuration.
This class is used with our KnockInAppFeedView
component, but it can also be used independently if you would like to build your own UI.
Properties
Methods
Examples
Authentication
Knock.shared.isAuthenticated()
Convenience method to determine if a user is currently authenticated for the Knock instance.
Returns: Bool
Params
Knock.shared.signIn()
Sets the userId and userToken for the current Knock instance. If the device token and pushChannelId were set previously, this will also attempt to register the token to the user that is being signed in. This does not get the user from the database nor does it return the full User object. You should consider using this in areas where you update your local user's state.
Params
Example
Knock.shared.signOut()
Sets the userId and userToken for the current Knock instance back to nil. If the device token and pushChannelId were set previously, this will also attempt to unregister the token to the user that is being signed out so they don't receive pushes they shouldn't get. You should call this when your user signs out
- Note: This will not clear the device token so that it can be accessed for the next user to login.
Example
User Management
Knock.shared.getUserId()
Fetch the userId that was set from the Knock.shared.signIn method.
Returns: String?
Knock.shared.getUser()
Returns the current user's profile stored in Knock. https://docs.knock.app/reference#get-user#get-user
Returns: Knock.User
Knock.shared.updateUser()
Updates the current user's profile in Knock. https://docs.knock.app/reference#get-user#get-user
Returns: Knock.User
Params
Channels/Push Notifications
Knock.shared.getUserChannelData()
Returns the channel data for the current user on the channel specified with channelId
.
Params
Returns: Knock.ChannelData
Knock.shared.updateUserChannelData()
Updates the channel data for the current user on the channel specified with channelId
.
Params
Returns: Knock.ChannelData
Knock.shared.getApnsDeviceToken()
Returns the apnsDeviceToken that was set from the Knock.shared.registerTokenForAPNS. If you use our KnockAppDelegate, the token registration will be handled for you automatically.
Returns String?
Knock.shared.registerTokenForAPNS()
Registers an Apple Push Notification Service token so that the device can receive remote push notifications. This is a convenience method that internally gets the channel data and searches for the token. If it exists, then it's already registered and it returns. If the data does not exists or the token is missing from the array, it's added. If the new token differs from the last token that was used on the device, the old token will be unregistered.
You can learn more about APNS here.
Params
Returns: Knock.ChannelData
Knock.shared.unregisterTokenForAPNS()
Unregisters the current deviceId associated to the user so that the device will no longer receive remote push notifications for the provided channelId.
Params
Returns: Knock.ChannelData
Knock.shared.getNotificationPermissionStatus()
Convenience method to determine whether or not the user is allowing Push Notifications for the app.
Returns: UNAuthorizationStatus
Knock.shared.requestNotificationPermission()
Requests push notification permissions to the user.
Params
Returns: UNAuthorizationStatus
Knock.shared.requestAndRegisterForPushNotifications()
Convenience method to request Push Notification permissions for the app, and then, if successful, registerForRemoteNotifications in order to get a device token.
Preferences
Knock.shared.getAllUserPreferences()
Returns all of the preference sets for the current user.
Returns: Knock.PreferenceSet
Knock.shared.getUserPreferences()
Returns a single preference set for the current user, specified by the preferenceId
. For the default preference set, set the preferenceId
to be default
.
Params
Returns: Knock.PreferenceSet
Knock.shared.setUserPreferences()
Updates the preference set specified by the preferenceId
with the new preferenceSet
.
Params
Returns: Knock.PreferenceSet
Messages
Knock.shared.getMessage()
Returns information about a single message specified by the messageId
.
https://docs.knock.app/reference#get-a-message
Params
Returns Knock.KnockMessage
Knock.shared.updateMessageStatus()
Updates the status of a single message specified by the message
or messageId
.
https://docs.knock.app/reference#undo-message-status
Params
Returns Knock.KnockMessage
Knock.shared.deleteMessageStatus()
Un-marks the given status on a message specified by the message
or messageId
, recording an event in the process.
https://docs.knock.app/reference#undo-message-status
Params
Returns Knock.KnockMessage
batchUpdateStatuses
Updates up to 50 messages with the given status in a single request specified by messageIds
or messages
.
https://docs.knock.app/reference#batch-update-message-status
Params
Returns [Knock.KnockMessage]
FeedManager
Knock.FeedManager.init()
Creates a new instance of a FeedManager
for interacting with a user's in-app notification feed.
Params
Example
Knock.shared.feedManager.connectToFeed()
Connects the feed instance to the real-time socket so that any new items published to the feed are received over the websocket.
Params
Knock.shared.feedManager.disconnectFromFeed()
Disconnects a connected real-time instance.
Knock.shared.feedManager.on()
Binds an event listener for incoming web socket events. Must have called connectToFeed
first.
Example
Knock.shared.feedManager.getUserFeedContent()
Retrieves the user's feed content for the feed. Can be scoped by passing options
, which also allows for paginating the contents of the feed using the before
and after
cursors.
Params
Returns Knock.Feed
Example
makeBulkStatusUpdate
Updates all of the items within the feed with the given status. Can be passed options
to scope the request further. Note: this method returns a BulkUpdate
via the Knock API, which is an async operation.
Params
Returns Knock.BulkOperation
Knock.FeedClientOptions
Used to scope a feed request.
Params