0

initWithAPIKey Exception : Invalid API key format'

I downloaded a project from Github: https://github.com/CometChat/ios-swift-chat-sdk-demo

And I changed API-Key and LicenseKey as in my CometChat Account. I am Getting this uncaught exception, when I Run my Project it runs fine and when I hit the button INITIALIZE CHAT then it shows this Exception. I am not getting why it is Coming, my Api-key and License is Valid.

my code:

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var btnInitializeChat: UIButton!
@IBOutlet weak var btnLoginSuperHero1: UIButton!
@IBOutlet weak var btnLoginSuperHero2: UIButton!
@IBOutlet weak var btnLaunchChat: UIButton!
@IBOutlet weak var pbLoading: UIView!
var licenseKey : String = "COMETCHAT-XXXX-XXXX-XXXX-XXXX"  // Replace this value with your CometChat License Key
var apiKey : String = "xxxxxxxxxxxxxxxxxxxxxx" // Replace the value with your CometChat Api Key;
var UID1 : String = "SUPERHERO1"
var UID2 : String = "SUPERHERO2"
var isCometOnDemand: Bool = true; // For CometChat Cloud Users, Please set this to true

var cometChat: CometChat = CometChat();
var readyUI: readyUIFIle = readyUIFIle();


override func viewDidLoad() {
    super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

override func viewWillAppear(_ animated: Bool) {
}

@IBAction func initializeChat() -> Void {
    self.showLoading(show:true);
    cometChat.initializeCometChat("", licenseKey:licenseKey, apikey:apiKey, isCometOnDemand:isCometOnDemand, success: {(response) in
        print(" successfully initailized")
        self.btnLoginSuperHero1.isEnabled = true;
        self.btnLoginSuperHero2.isEnabled = true;
        self.showLoading(show:false);
    },failure:{(error) in
        print(" Failed to initialized ")
        self.showLoading(show:false);
    });
}


@IBAction func loginWithSuperHero1() -> Void {
    self.showLoading(show:true);
    cometChat.login(withUID:UID1,success:{(response) in
        print(" Successful login ")
        self.btnLaunchChat.isEnabled = true;
        self.showLoading(show:false);
    },failure:{(error) in
        print(" Failed login ")
        self.showLoading(show:false);
    });
}

@IBAction func loginWithSuperHero2() -> Void {
    self.showLoading(show:true);
    cometChat.login(withUID:UID2,success:{(response) in
        print(" Successful login ")
         self.btnLaunchChat.isEnabled = true;
        self.showLoading(show:false);
    },failure:{(error) in
        print(" Failed login ")
        self.showLoading(show:false);
    });
}

@IBAction func launchChat() -> Void {
    let isFullScreen : Bool = true;
    self.showLoading(show:true);
    readyUI.launchCometChat(isFullScreen, observer: self, userInfo: { (response) in
        print("Launch ReadyUI Successfull  ")
        self.showLoading(show:false);
    }, groupInfo: { (response) in

    }, onMessageReceive: { (response) in

    }, success: { (response) in

    }, failure: { (error) in
        print(" Failed ReadyUI lauch ")
        self.showLoading(show:false);
    }, onLogout: { (response) in
        print(" Logout ")
    })

}

func showLoading(show:Bool) -> Void {
    if(show){
        pbLoading.isHidden = false;
    }else{
        pbLoading.isHidden = true;
    }
}
}

please give me Solution.

Bhavin Kansagara
  • 2,866
  • 1
  • 16
  • 20
Kumar Lav
  • 5
  • 1
  • 5
  • Hi and welcome to SO! It ma be hard to help you without seeing your code, but I'd also encourage you to contact their support (or open an issue on their github) since the team behind CometChat is most likely to help you. – Losiowaty Aug 20 '18 at 19:50
  • Sir, Now I have Mentioned my Code please see it. here API key and License Key is Dummy but in my code its real. – Kumar Lav Aug 21 '18 at 05:22
  • @KumarLav you can create an issue in their GitHub project: https://github.com/CometChat/ios-swift-chat-sdk-demo/issues – Alec Smart Aug 21 '18 at 07:09

1 Answers1

-1

Everything looks fine in your code. Maybe there is an issue with your pods file. Please make sure the following is present in your pods file-

pod 'MessageSDKFramework','~> 7.9.0'
pod 'cometchat-ui','~> 7.9.0'
pod ‘Firebase/Auth’,'~> 4.8.2'
pod ‘Firebase/Database’,'~> 4.8.2'

If you still face an issue, you can create a support ticket: https://www.cometchat.com/contact-support

(This account is affiliated with CometChat.com)

CometChat
  • 97
  • 3