'How to fix "Invalid API key format" while implement the comet-chat in iOS
The problem is that when I am going to initialize the comet-chat
then they generate the error like -
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'initWithAPIKey Exception : Invalid API key format' "
I have tried
step.1 I have Install all the below pods
Firebase (4.8.2)
FirebaseAnalytics (4.0.9)
FirebaseAuth (4.4.2)
FirebaseCore (4.0.14)
FirebaseDatabase (4.1.4)
FirebaseInstanceID (2.0.10)
GTMSessionFetcher (1.1.15)
GoogleToolboxForMac (2.1.4)
MessageSDKFramework (7.0.23)
cometchat-ui (7.0.23)
leveldb-library (1.20)
nanopb (0.3.8)
step 2. Then Code of My viewcontroller (I am Going to initialize the comet-chat
first)
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 = "XXXX-XXXX-XXXX-XXXX-XXXXX" // Replace this value with your CometChat License Key
var apiKey : String = "xxxxxxxxxxxxxxxxx" // Replace the value with your CometChat Api Key;
var UID1 : String = "xxxxxx"
var UID2 : String = "yyyyyy"
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("http://www.gamegods.com", 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;
}
}
}
Solution 1:[1]
It looks like you are using our Cloud SDK
with a Self-Hosted installation. Please note that the code above is only for our Cloud SDK
and will not work with your Self-Hosted solution.
If you need further assistance, you can email https://www.cometchat.com/contact-support
(This account is affiliated with CometChat.com)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | General Grievance |