代码之家  ›  专栏  ›  技术社区  ›  AaoIi

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

  •  1
  • AaoIi  · 技术社区  · 7 年前

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

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

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

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

    我们还尝试向主题发送通知,主题是 push_channel

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

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

    • 我们将firebase中的服务器遗留密钥添加到Cometchat>设置>移动,因为时间长了,它仍然不工作。

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

    cometChatHolder.login(userUuid: "\(id)", userName: username)
    

    然后在以后的任何时候开始聊天并启动聊天室,我会呼叫:

    cometChatHolder.startChat(userUuid: "the id of the user to start the chat with", delegate: self)
    

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

    更新(修复步骤):

    1 回复  |  直到 7 年前
        1
  •  5
  •   CometChat    7 年前

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

    1. 将旧服务器密钥添加为CometChat管理面板中设置->下的Firebase服务器密钥;移动标签

    请您也检查一下以下几点是否得到了正确实施?这些人负责从Firebase接收推送通知-

    1. [[FIRMessaging messaging] subscribeToTopic:[NSString stringWithFormat:@"%@",push_channel]];
      

    请参阅附件中的图片,以便更好地理解。

    Adding Legacy server key to Admin Panel

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

    十二月四日更新

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

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

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

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

    推荐文章