我已经在我的应用程序中实现了 Cometchat SDK,并且我还按照通过 firebase 的所有要求将服务器旧密钥添加到 Cometchat 控制台并使用“push_channel”订阅频道并使用以下命令:
Messaging.messaging().subscribe(toTopic: push_channel)
假设 iOS 设备向另一台 iOS 设备发送消息甚至尝试呼叫,并且应用程序已关闭,没有通知会通知其他设备正在接收呼叫或消息,直到用户打开应用程序然后打开 CometChat 可以聊天或查看消息,我错过了什么吗?Cometchat 是一个 VOIP,应该唤醒应用程序吗?或不 ?
更新:
我们尝试向目标设备 fcm 令牌发送通知,它工作正常并被成功接收。(通过 firebase 控制台)。
我们还尝试向作为直通火力基地的主题发送通知,push_channel
并且任何设备都没有收到通知。(通过firebase控制台)。
我们确信我们在 firebase 和 cometchat 控制台中实现了所有必需的信息。
担忧: 我有一个担忧,但不应该是问题,但我会说我们使用的是推送通知密钥而不是 firebase 云消息证书中的 p12,但这不应该是问题吗?
代码和更新
我们将来自 firebase 的服务器旧密钥添加到 Cometchat > 设置 > 移动中,因为很长时间以来它仍然无法正常工作。
下面的代码是我用来通信或实例化 Cometchat 并注册令牌的类,尽管告诉我我做错了什么,即使你的文档中没有完整的覆盖示例,所以你去:
这是 CometChatHandler 类:
fileprivate let cometChat: CometChat = CometChat()
fileprivate let readyUI: readyUIFIle = readyUIFIle()
fileprivate let isCometOnDemand: Bool = true // For CometChat Cloud Users, Please set this to true
init(apiKey: String, licenseKey: String) {
cometChat.initializeCometChat("", licenseKey: licenseKey, apikey: apiKey, isCometOnDemand: isCometOnDemand, success: {(response) in
}, failure: { (error) in
})
}
func login(userUuid: String, userName: String) {
if self.cometChat.isUserLoggedIn() {
print("user already login")
} else {
let UID = "User_\(userUuid)"
cometChat.login(withUID: UID, success: { (dictionary: [AnyHashable: Any]!) -> () in
}, failure: { (error: Error!) -> () in
self.createUser(userUuid: userUuid, userName: userName)
})
}
}
func logout() {
cometChat.logout({ dictionary in
}, failure: { error in
})
}
func startChat(userUuid: String, delegate: UIViewController) {
if self.cometChat.isUserLoggedIn() {
self.cometChat.subscribeCallbacks(true, onMyInfoReceived: { (response) in
print("onMyInfoReceived \(String(describing: response))")
if let res = response as? Dictionary<String,Any>{
let push_channel = res["push_channel"] as? String ?? ""
print(push_channel)
DispatchQueue.main.async {
Messaging.messaging().subscribe(toTopic: push_channel)
}
}
}, onUserListReceived: { (response) in
print("onUserListReceived \(String(describing: response))")
}, onMessageReceived: { (response) in
print("onMessageReceived \(String(describing: response))")
}, onAVChatMessageReceived: { (response) in
print("onAVChatMessageReceived \(String(describing: response))")
}, onActionMessageReceived: { (response) in
print("onActionMessageReceived \(String(describing: response))")
}, onGroupListReceived: { (response) in
print("onGroupListReceived \(String(describing: response))")
}, onGroupMessageReceived: { (response) in
print("onGroupMessageReceived \(String(describing: response))")
}, onGroupAVChatMessageReceived: { (response) in
print("onGroupAVChatMessageReceived \(String(describing: response))")
}, onGroupActionMessageReceived: { (response) in
print("onGroupActionMessageReceived \(String(describing: response))")
}, onRecentChatListReceived: { (response) in
print("onRecentChatListReceived \(String(describing: response))")
}, onAnnouncementReceived: { (response) in
print("onAnnouncementReceived \(String(describing: response))")
}) { (error) in
}
openChatUI(userUuid: userUuid, delegate: delegate)
} else {
print("User not login")
}
}
#warning("TODO for left to right")
private func openChatUI(userUuid: String, delegate: UIViewController, isGroup: Bool = false, isFullScreen: Bool = true) {
self.readyUI.launchCometChat(userUuid, isGroup: isGroup,
isFullScreen: isFullScreen,
observer: delegate,
setBackButton: true, userInfo: { (response) in
print("Success Login with these data \(String(describing: response))")
}, groupInfo: { (response) in
print("Success groupInfo with these data \(String(describing: response))")
}, onMessageReceive: { (response) in
print("Success onMessageReceive with these data \(String(describing: response))")
}, success: { (response) in
print("Success success with these data \(String(describing: response))")
}, failure: { (error) in
}, onLogout: { (response) in
print("Success onLogout with these data \(String(describing: response))")
})
}
private func createUser(userUuid: String, userName: String) {
let UID = "User_\(userUuid)"
cometChat.createUser(UID,
userName: userName,
avatarUrl: "",
profileUrl: "",
role: "",
success: { (_) in
self.login(userUuid: userUuid, userName: userName)
}) { (error) in
print(error?.localizedDescription ?? "")
}
}
要在开始使用我的应用程序时登录用户,我使用 Cometchat 登录用户:
cometChatHolder.login(userUuid: "\(id)", userName: username)
然后稍后随时开始聊天并启动我调用的聊天:
cometChatHolder.startChat(userUuid: "the id of the user to start the chat with", delegate: self)
我真的陷入了死胡同,我希望我能得到一些帮助来解决这个问题,因为我别无选择。
更新(修复步骤):这就是我修复问题的方法,不要依赖 SDK 告诉你用户已登录,所以每次你应该启动 cometChat 然后登录用户然后打开聊天,什么我正在做的是检查用户是否通过 SDK 登录然后打开 SDK,这就是解决问题的技巧。