gpt4 book ai didi

ios - Cometchat 不会在通话或收到消息时唤醒应用程序

转载 作者:搜寻专家 更新时间:2023-11-01 06:12:15 24 4
gpt4 key购买 nike

我已经在我的应用程序中实现了 Cometchat SDK,并且我还按照通过 firebase 的所有要求将服务器遗留 key 添加到 Cometchat 控制台并使用“push_channel”订阅 channel 并使用以下命令:

 Messaging.messaging().subscribe(toTopic: push_channel)

假设 iOS 设备向另一台 iOS 设备发送消息或什至尝试调用,并且该应用程序已关闭,没有通知发生以通知另一台设备正在接收调用或消息,直到用户打开应用程序,然后打开 CometChat 以便能够聊天或查看消息,我是否遗漏了什么? Cometchat 是一个 VOIP,应该在通话时唤醒应用程序吗?还是不是?

更新:

我们尝试向目标设备 fcm token 发送通知,它工作正常并被成功接收。(通过 firebase 控制台)。

我们还尝试通过 fire base 向 push_channel 主题发送通知,但任何设备都没有收到通知。 (通过 firebase 控制台)。

我们确信我们在 firebase 和 cometchat 控制台中实现了所有必需的信息。

关注:我有一个顾虑,但不应该是问题,但我会说我们在 firebase 云消息证书中使用推送通知 key 而不是 p12,但这不应该是问题吗?

代码和更新

  • 我们将来自 firebase 的服务器遗留 key 添加到 Cometchat >​​ 设置 > 移动中,很长时间以来它仍然无法正常工作。

  • 下面的代码是我用来通信或实例化 Cometchat 并注册 token 的类,请告诉我我做错了什么,即使您的文档中没有完整的示例所以给你:

这是 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,这就是解决问题的技巧。

最佳答案

您似乎没有在 CometChat 管理面板中添加 Firebase Legacy key 。请按照以下步骤操作:

  1. 获取“旧服务器 key ”以配置 Firebase 推送通知服务。
  2. 在 CometChat 管理面板的“设置”->“移动”选项卡下将旧版服务器 key 添加为 Firebase 服务器 key

能否请您也检查以下几点是否已正确执行?这些是负责从 Firebase 接收推送通知的人 -

  1. 订阅一个 channel ,您将从中获得推送通知。当您使用 SDK 调用 subscribe 方法时,您将从 onMyInfoReceived() 回调中收到的响应中获取此 channel 。回调的响应包含一个名为“push_channel”的键。这包含推送通知 channel 。订阅此 channel 后,您将开始接收一对一聊天的推送通知。您可以使用以下方法订阅收到的 channel :

    [[FIRMessaging messaging] subscribeToTopic:[NSString stringWithFormat:@"%@",push_channel]];
  1. 对于组内的推送通知,您将从 joinGroup 方法的成功回调中收到的响应中获取“push_channel”。订阅此 channel 后,您将开始接收群组的推送通知。

请参阅附图以获得更好的理解。

Adding Legacy server key to Admin Panel

有关更多资源,您可以引用 iOS 中推送通知的文档:https://developer.cometchat.com/docs/ios-push-notifications

12 月 4 日更新:

我们创建了一个示例应用程序并向其添加了 Firebase 推送通知。您可以从以下网址下载该项目:

https://temp.cometchat.com/ios-swift-chat-sdk-demo-master.zip

请引用 ViewController.swift 和 AppDelegate.swift 文件中的代码。

希望这能解决问题。让我们知道问题是否仍然存在。

披露 - 此帐户归 CometChat 团队所有。

关于ios - Cometchat 不会在通话或收到消息时唤醒应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53462714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com