PubNub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let PubNub handle sending and receiving data across the world in less than 100ms.
This SDK offers a set of handy methods to create your own feature-rich chat or add a chat to your existing application.
It exposes various PubNub APIs with twists:
- Tailored specifically to the chat use case by offering easy-to-use methods that let you do exactly what you want, like startTyping() (a message) or join() (a channel).
- Meant to be easy & intuitive to use as it focuses on features you would most likely build in your chat app, not PubNub APIs and all the technicalities behind them.
- Offers new chat options, like quotes, threads, or read receipts, that let you build a full-fledged app quickly.
- iOS 14.0+ / macOS 11.0+ / tvOS 14.0+
- Xcode 15+
- Swift 5+
You will need the publish and subscribe keys to authenticate your app. Get your keys from the Admin Portal.
- Create or open your project inside Xcode.
- Navigate to File -> Add Package Dependencies.
- Search for
https://github.com/pubnub/swift-chat-sdk
- From the Dependency Rule drop-down list, select Exact. In the version input field, type
0.9.3-dev
- Click the Add Package button.
For more information see Apple's guide on Adding Package Dependencies to Your App
-
Import the module named
PubNubSwiftChatSDK
andPubNubSDK
inside any of your Swift source file:import PubNubSDK import PubNubSwiftChatSDK // <- Here is our PubNubSwiftChatSDK module import.
-
Create
PubNubConfiguration
object andChatImpl
object:let pubNubConfiguration = PubNubConfiguration( publishKey: "myPublishKey", subscribeKey: "mySubscribeKey", userId: "myUniqueUserId" // Fill in the necessary parameters for PubNubConfiguration if needed ) let chat = ChatImpl( // Fill in the necessary parameters for ChatConfiguration if needed chatConfiguration: ChatConfiguration(), pubNubConfiguration: pubNubConfiguration )
-
Initialize a
chat
object:chat.initialize() { switch $0 { case .success(_): print("Chat object initialized") case let .failure(error): print("Unable to initialize due to error \(error)") } }
If you need help or have a general question, contact support@pubnub.com.
The PubNub Swift Chat SDK is released under the PubNub Software Development Kit License
.
See LICENSE for details.