/swift-chat-sdk

PubNub Swift Chat SDK

Primary LanguageSwiftOtherNOASSERTION

PubNub Swift Chat SDK

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.

Table Of Contents

Requirements

  • iOS 14.0+ (support for other platforms is coming in future releases)
  • Xcode 15+
  • Swift 5+

Get keys

You will need the publish and subscribe keys to authenticate your app. Get your keys from the Admin Portal.

Set up your project

  1. Create or open your project inside Xcode.
  2. Navigate to File -> Add Package Dependencies.
  3. Search for https://github.com/pubnub/swift-chat-sdk
  4. From the Dependency Rule drop-down list, select Exact. In the version input field, type 0.8.0-dev
  5. Click the Add Package button.

For more information see Apple's guide on Adding Package Dependencies to Your App

Configure

  1. Import the module named PubNubSwiftChatSDK and PubNubSDK inside any of your Swift source file:

    import PubNubSDK
    import PubNubSwiftChatSDK // <- Here is our PubNubSwiftChatSDK module import.
  2. Create PubNubConfiguration object and ChatImpl 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
    )
  3. 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)")
      }    
    }

Documentation

Support

If you need help or have a general question, contact support@pubnub.com.

License

The PubNub Swift Chat SDK is released under the PubNub Software Development Kit License.

See LICENSE for details.