首页 > 解决方案 > Cometchat 不会在通话或收到消息时唤醒应用

问题描述

我已经在我的应用程序中实现了 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,但这不应该是问题吗?

代码和更新

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

标签: iosswiftcometchat

解决方案


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

  1. 获取“Legacy Server Key”来配置 Firebase 推送通知服务。
  2. 在 CometChat 管理面板中的 Settings -> Mobile 选项卡下将 Legacy Server Key 添加为 Firebase 服务器密钥

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

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

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

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

将旧服务器密钥添加到管理面板

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

12 月 4 日更新

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

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

请参考 ViewController.swift 和 AppDelegate.swift 文件中的代码。

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

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


推荐阅读