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

Aao*_*oIi 2 ios swift cometchat

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

 Messaging.messaging().subscribe(toTopic: push_channel)
Run Code Online (Sandbox Code Playgroud)

假设 iOS 设备向另一台 iOS 设备发送消息甚至尝试拨打电话,而该应用程序已关闭,则不会有任何通知通知另一台设备正在收到呼叫或消息,直到用户打开该应用程序然后打开 CometChat 可以聊天或查看消息,我错过了什么吗?Cometchat 是一个 VOIP,应该在通话时唤醒应用程序吗?或不 ?

更新:

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

我们还尝试向主题发送通知,这是 push_channel通过火力基地,并且没有收到任何设备的通知。(通过firebase控制台)。

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

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

代码和更新

  • 我们将 firebase 中的服务器遗留密钥添加到 Cometchat >​​ Settings > Mobile 中,因为很长时间以来它仍然无法正常工作。

  • 下面的代码是我用来通信或实例化 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 ?? "")
    }
}
Run Code Online (Sandbox Code Playgroud)

要在开始使用我的应用程序时登录用户,我使用 Cometchat 登录用户:

cometChatHolder.login(userUuid: "\(id)", userName: username)
Run Code Online (Sandbox Code Playgroud)

然后稍后随时开始聊天并启动我调用的聊天:

cometChatHolder.startChat(userUuid: "the id of the user to start the chat with", delegate: self)
Run Code Online (Sandbox Code Playgroud)

我真的陷入了死胡同,我希望我能得到一些帮助来解决这个问题,因为我别无选择。

更新(修复步骤):这就是我解决问题的方法,不要依赖SDK告诉你用户已登录,所以每次你应该启动cometChat然后登录用户然后打开聊天,什么我正在做的是检查用户是否通过 SDK 登录然后打开 SDK,这就是解决问题的技巧。

Com*_*hat 5

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

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

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

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

    [[FIRMessaging messaging] subscribeToTopic:[NSString stringWithFormat:@"%@",push_channel]];
    
    Run Code Online (Sandbox Code Playgroud)
  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 团队所有。

  • 感谢您花时间将您的回答风格调整为 Stack Overflow;我认为您正在取得巨大进步并帮助您的社区。 (4认同)