Ios Cometchat不';t在收到呼叫或消息时唤醒应用程序
我已经在我的应用程序中实现了Cometchat SDK,我还遵循了firebase的所有要求,将服务器遗留密钥添加到Cometchat控制台,并使用“push_channel”订阅频道,并使用以下命令:Ios Cometchat不';t在收到呼叫或消息时唤醒应用程序,ios,swift,cometchat,Ios,Swift,Cometchat,我已经在我的应用程序中实现了Cometchat SDK,我还遵循了firebase的所有要求,将服务器遗留密钥添加到Cometchat控制台,并使用“push_channel”订阅频道,并使用以下命令: Messaging.messaging().subscribe(toTopic: push_channel) 假设iOS设备向另一个iOS设备发送消息,甚至尝试呼叫,并且应用程序已关闭,没有通知通知另一个设备正在接收呼叫或消息,直到用户打开应用程序,然后打开CometChat以便能够聊天或查
Messaging.messaging().subscribe(toTopic: push_channel)
假设iOS设备向另一个iOS设备发送消息,甚至尝试呼叫,并且应用程序已关闭,没有通知通知另一个设备正在接收呼叫或消息,直到用户打开应用程序,然后打开CometChat以便能够聊天或查看消息,我是否遗漏了什么?Cometchat是一种VOIP,应该在通话时唤醒应用程序吗?还是不
更新:
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 ?? "")
}
}
我们尝试将通知发送到目标设备fcm令牌,它工作正常并被成功接收。(通过firebase控制台)
我们还尝试通过fire base向主题(即推送频道)发送通知,但没有向任何设备接收通知。(通过firebase控制台)
我们确信我们在firebase和cometchat控制台中实现了所有必需的信息
关注点:
我有一个顾虑,但这不应该是问题所在,但我要说的是,我们在firebase云消息证书中使用的是推送通知密钥,而不是p12,但这不应该是问题所在吗
编码和更新
- 我们将firebase中的服务器遗留密钥添加到Cometchat>Settings>Mobile中,因为时间很长,它仍然无法工作
- 下面的代码是我用来通信或实例化Cometchat并注册令牌的类,告诉我我做错了什么,即使您的文档中没有完整的覆盖示例,也可以这样做:
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 ?? "")
}
}
然后在以后的任何时候开始聊天并启动聊天室,我会呼叫:
cometChatHolder.startChat(userUuid: "the id of the user to start the chat with", delegate: self)
我真的陷入了死胡同,我希望我能得到一些帮助来解决这个问题,因为我已经没有选择了
更新(修复步骤):这就是我解决问题的方法,不要依赖SDK告诉您用户已登录,因此每次您都应该启动cometChat,然后登录用户,然后打开聊天室,我所做的是检查用户是否通过SDK登录,然后打开SDK,这就是解决问题的技巧。您似乎没有在CometChat管理面板中添加Firebase旧版密钥。请按照以下步骤操作:
[[FirmMessageing messaging]订阅主题:[NSString stringWithFormat:@“%@”,推送频道]];
披露-此帐户归CometChat团队所有 感谢您花时间调整您的回答方式以适应堆栈溢出;我认为您在这里取得了巨大的进步并帮助了您的社区。@CometChat,我已经更新了我的问题,您的建议都没有帮助我。@AaoIi我们已经更新了答案。请检查并让我们知道这是否解决了问题。