Skip to content

knocklabs/knock-swift

Repository files navigation

Official Knock iOS SDK

GitHub Release CocoaPods Carthage compatible Swift Package Manager compatible

min swift version is 5.3 min ios version is 16 GitHub license


Knock is a flexible, reliable notifications infrastructure that's built to scale with you. Use our iOS SDK to engage users with in-app feeds, setup push notifications, and manage notification preferences.


Documentation

See the documentation for full documentation.

Migrations

See the Migration Guide if upgrading from a previous version.

Example App

See the iOS Example App for more examples.

Installation

Swift Package Manager

There are two ways to add this as a dependency using the Swift Package Manager:

  1. Using Xcode
  2. Manually via Package.swift

Using Xcode

  1. Open your Xcode project and select File -> Add Packages...
Screenshot 2023-06-27 at 19 41 32
  1. Search for https://github.com/knocklabs/knock-swift.git and then click Add Package Note: We recommend that you set the Dependency Rule to Up to Next Major Version. While we encourage you to keep your app up to date with the latest SDK, major versions can include breaking changes or new features that require your attention.
Screenshot 2023-06-27 at 19 42 09

Manually via Package.swift

If you are managing dependencies using the Package.swift file, just add this to you dependencies array:

dependencies: [
    .package(url: "https://github.com/knocklabs/knock-swift.git", .upToNextMajor(from: "1.2.4"))
]

Cocoapods

Add the dependency to your Podfile:

platform :ios, '16.0'
use_frameworks!

target 'MyApp' do
  pod 'Knock', '~> 1.2.4'
end

Carthage

  1. Add this line to your Cartfile:
github "knocklabs/knock-swift" ~> 1.1.0

Manually

As a last option, you could manually copy the files inside the Sources folder to your project.

Import and start using the SDK

You can now start using the SDK:

import Knock

/* 
 Setup the shared Knock instance as soon as you can. 
 Note: pushChannelId is required if you want to use our KnockAppDelegate helper. 
 Otherwise, this field is optional.
*/
try? Knock.shared.setup(publishableKey: "your-pk", pushChannelId: "apns-push-channel-id")

// Once you know the Knock UserId, sign the user into the shared Knock instance.
await Knock.shared.signIn(userId: "userid", userToken: nil)

How to Contribute

Community contributions are welcome! If you'd like to contribute, please read our contribution guide.

License

This project is licensed under the MIT license.

See LICENSE for more information.