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

Cometchat doesn't awake the app on call or message received

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

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

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

更新:

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

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

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

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

编码和更新

这是 CometChatHandler class :

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 密钥。请按照以下步骤操作:

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

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

  1. 正在订阅一个频道,您将从中获得推送通知。当您使用回调的 SDK.The 响应调用订阅方法时,您将从 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 团队所有。