由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“initWithAPIKey 异常:无效的 API 密钥格式”
Posted
技术标签:
【中文标题】由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“initWithAPIKey 异常:无效的 API 密钥格式”【英文标题】:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'initWithAPIKey Exception : Invalid API key format' 【发布时间】:2018-08-20 11:54:52 【问题描述】:initWithAPIKey 异常:无效的 API 密钥格式'
我从 Github 下载了一个项目:https://github.com/CometChat/ios-swift-chat-sdk-demo
我更改了我的 CometChat 帐户中的 API-Key 和 LicenseKey。 我遇到了这个未捕获的异常,当我运行我的项目时它运行良好,当我点击按钮 INITIALIZE CHAT 时,它会显示这个异常。我不明白为什么会出现,我的 Api 密钥和许可证有效。
我的代码:
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;
请给我解决方案。
【问题讨论】:
您好,欢迎来到 SO!没有看到你的代码可能很难帮助你,但我也鼓励你联系他们的支持(或在他们的 github 上打开一个问题),因为 CometChat 背后的团队最有可能帮助你。 先生,现在我提到了我的代码,请看。这里 API 密钥和许可证密钥是虚拟的,但在我的代码中是真实的。 @KumarLav 你可以在他们的 GitHub 项目中创建一个问题:github.com/CometChat/ios-swift-chat-sdk-demo/issues 【参考方案1】:您的代码中的一切看起来都很好。也许你的 pods 文件有问题。请确保您的 pods 文件中存在以下内容-
pod 'MessageSDKFramework','~> 7.9.0'
pod 'cometchat-ui','~> 7.9.0'
pod ‘Firebase/Auth’,'~> 4.8.2'
pod ‘Firebase/Database’,'~> 4.8.2'
如果您仍然遇到问题,可以创建支持票:https://www.cometchat.com/contact-support
(此帐户隶属于 CometChat.com)
【讨论】:
征求异地跟进是一种边缘行为。以上是关于由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“initWithAPIKey 异常:无效的 API 密钥格式”的主要内容,如果未能解决你的问题,请参考以下文章
由于未捕获的异常而终止应用程序 [UIImageView _isResizable]
由于未捕获的异常“NSInternalInconsistencyException”错误而终止应用程序