GithubHelp home page GithubHelp logo

nakul-cometchat / chat-sdk-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cometchat/chat-sdk-ios

0.0 0.0 0.0 747.09 MB

Text Chat SDK for iOS

Home Page: https://www.cometchat.com

Ruby 54.47% Swift 45.53%

chat-sdk-ios's Introduction

CometChat

CometChat iOS Chat SDK

CometChat enables you to add voice, video & text chat for your website & app.


Prerequisites ⭐

Before you begin, ensure you have met the following requirements:

✅   You have installed the latest version of Xcode. (Above Xcode 12 Recommended)

✅   iOS Chat SDK works for iOS devices from iOS 11 and above.


Installing iOS Chat SDK

1. Setup 🔧

To install iOS Chat SDK, you need to first register on CometChat Dashboard. Click here to sign up.

i. Get your Application Keys 🔑

  • Create a new app
  • Head over to the Quick Start or API & Auth Keys section and note the App ID, Auth Key, and Region.

ii. Add the CometChatPro Dependency

We recommend using CocoaPods, as they are the most advanced way of managing iOS project dependencies. Open a terminal window, move to your project directory, and then create a Podfile by running the following command

Create podfile using below command.

$ pod init

Add the following lines to the Podfile.

________________________________________________________________

For Xcode 12 and above:

platform :ios, '11.0'
use_frameworks!

target 'YourApp' do
     pod 'CometChatSDK', '4.0.45'
end
________________________________________________________________

v3.0.1+ onwards, Voice & Video Calling functionality has been moved to a separate framework. Please add the following pod to your app Podfile in case you plan on using the Voice and Video Calling feature.

________________________________________________________________

For Xcode 12 and above:

platform :ios, '11.0'
use_frameworks!

target 'YourApp' do
     pod 'CometChatSDK', '4.0.45'
     pod 'CometChatCallsSDK', '4.0.2'
end
________________________________________________________________

And then install the CometChatPro framework through CocoaPods.

pod install

If you're facing any issues while installing pods then use the below command.

pod install --repo-update

2. Configure CometChat inside your app

i. Initialize CometChat 🌟

The init() method initializes the settings required for CometChat. We suggest calling the init() method on app startup, preferably in the didFinishLaunchingWithOptions() method of the Application class.

import CometChatSDK

class AppDelegate: UIResponder, UIApplicationDelegate{

   var window: UIWindow?
   let appId: String = "ENTER APP ID"
   let region: String = "ENTER REGION CODE"
    
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

  let mySettings = AppSettings.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region: region).build()
  CometChat(appId: appId ,appSettings: mySettings,onSuccess: { (isSuccess) in
  
                print("CometChat SDK intialise successfully.")

        }) { (error) in
            print("CometChat SDK failed intialise with error: \(error.errorDescription)")
        }
        return true
    }
}

Note : Make sure you replace the APP_ID with your CometChat appId and region with your app region in the above code.


ii. Create User 👤

Once initialization is successful, you will need to create a user. To create the users on the fly, you can use the createUser() method. This method takes a User object and the Auth Key as input parameters and returns the created User object if the request is successful.

let newUser : User = User(uid: "user1", name: "Kevin") // Replace with your uid and the name for the user to be created.
let authKey = "authKey" // Replace with your Auth Key.
CometChat.createUser(user: newUser, apiKey: authKey, onSuccess: { (User) in
      print("User created successfully. \(User.stringValue())")
  }) { (error) in
     print("The error is \(String(describing: error?.description))")
}

iii. Log in your User 👤

The login() method returns the User object containing all the information of the logged-in user.

let uid    = "SUPERHERO1"
let authKey = "ENTER AUTH KEY"

CometChat.login(UID: uid, apiKey: authKey, onSuccess: { (user) in

  print("Login successful: " + user.stringValue())

}) { (error) in

  print("Login failed with error: " + error.errorDescription);

}

Note :

  • Make sure you replace the authKey with your CometChat Auth Key in the above code.

  • We have set up 5 users for testing having UIDs: SUPERHERO1, SUPERHERO2, SUPERHERO3, SUPERHERO4, and SUPERHERO5.


Checkout our sample apps

Swift:

Visit our Swift sample app repo to run the Swift sample app.


Help and Support

For issues running the project or integrating with our UI Kits, consult our documentation or create a support ticket or seek real-time support via the CometChat Dashboard.

chat-sdk-ios's People

Contributors

abhisheksaralaya13 avatar ghanshyammansata avatar pushpsenairekar2911 avatar jeetkapadia avatar nishanttiwarins avatar suryansh-cometchat avatar ketanyekale avatar darshanbhanushali avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.