简体   繁体   English

Mesibo 聊天 sdk 使用 swift 集成到 ios 中

[英]Mesibo chat sdk integrate in ios using swift

I am setting mesibo chat sdk. auth key generated and set it to我正在设置mesibo chat sdk. auth key generated and set it to sdk. auth key generated and set it to Appdelegate.Create` a user in Mesibo dashboard and trying to send or receive messages but could not get any messages. sdk. auth key generated and set it to Appdelegate.Create` Mesibo 仪表板中的用户并尝试发送或接收消息但无法获取任何消息。 Error showing on dashboard:-仪表板上显示的错误:-

"failed to send messages". “发送消息失败”。

Use mesibo framework a.Implement delegate methods for this.使用 mesibo 框架 a.为此实现委托方法。

Appdelegate code in didfinish launch. didfinish 启动中的Appdelegate代码。

Mesibo.getInstance()!.setAccessToken("1c06e8813355b567b0f79162d5ff786e96b419122ade88ef68")
Mesibo.getInstance()!.setSecureConnection(true)
Mesibo.getInstance()!.start()

Code in view controller:-视图控制器中的代码:-

MesiboUI.launchMessageViewController(self, profile:nil)
Mesibo.getInstance()?.start()

I expect the instant chat from one to one.我期待一对一的即时聊天。

Try with adding the listener in didFinishLaunching method:尝试在 didFinishLaunching 方法中添加监听器:

[MesiboInstance addListener:self]; [MesiboInstance addListener:self];

    **Please check in Appdelegate : 

        mesiboInstance?.setAccessToken("youraccesstoken")

        Mesibo.getInstance()?.addListener(self)
        Mesibo.getInstance()?.start()

    //MARK:- Get user permission for using camera , audio


    extension AppDelegate {

        func checkCameraAccess() {
            switch AVCaptureDevice.authorizationStatus(for: .video) {
                case .denied:
                    print("Denied, request permission from settings line 288")
                //presentCameraSettings()
                case .restricted:
                    print("Restricted, device owner must approve line 291")
                case .authorized:
                    print("Authorized, proceed line 293")
                case .notDetermined:
                    AVCaptureDevice.requestAccess(for: .video) { success in
                        if success {
                            print("Permission granted, proceed line 297")
                        } else {
                            print("Permission denied")
                        }
                }
            }
        }

        func checkMicPermission() {
            switch AVAudioSession.sharedInstance().recordPermission {
                case AVAudioSession.RecordPermission.granted:
                    print("mic Permission granted , line 305")
                    break
                case AVAudioSession.RecordPermission.denied:
                    print("mic Permission not granted , line 309")
                    break
                case AVAudioSession.RecordPermission.undetermined:
                    AVAudioSession.sharedInstance().requestRecordPermission({ (granted) in
                        if granted {
                            print("mic Permission granted , line 312")

                        } else {
                            print("mic Permission denied , line 314")
                        }
                    })
                default:
                    break
            }
        }

    }
    extension AppDelegate {

        func setRootController(_ controller: UIViewController?) {
            window!.rootViewController = controller
            window!.rootViewController = controller
            window!.makeKeyAndVisible()
            //[[UIApplication sharedApplication].keyWindow setRootViewController:rootViewController];
        }
        public func mesibo_(onGetMenu parent: Any!, type: Int32, profile: MesiboUserProfile!) -> [Any]! {

            var btns: [AnyHashable]? = nil

            if type == 0 {
                let button = UIButton(type: .custom)
                button.setImage(UIImage(named: "ic_message_white"), for: .normal)
                button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
                button.tag = 0

                let button1 = UIButton(type: .custom)
                button1.setImage(UIImage(named: "ic_more_vert_white"), for: .normal)
                button1.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
                button1.tag = 1

                btns = [button, button1]
            } else {
                if profile != nil && profile?.address != nil {
                    let button = UIButton(type: .custom)
                    button.setImage(UIImage(named: "ic_call_white"), for: .normal)
                    button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
                    button.tag = 0
                    let vbutton = UIButton(type: .custom)
                    vbutton.setImage(UIImage(named: "ic_videocam_white"), for: .normal)
                    vbutton.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
                    vbutton.tag = 1

                    btns = [vbutton, button]
                }
            }

            return btns

        }

        public func mesibo_(onMenuItemSelected parent: Any!, type: Int32, profile: MesiboUserProfile!, item: Int32) -> Bool {

            // userlist menu are active
            if type == 0 {
                // USERLIST
                if item == 1 {
                    //item == 0 is reserved
    //                MesiboUIManager.launchSettings(parent as! UIViewController)
                }
            } else {
                // MESSAGEBOX
                if item == 0 {
                    print("Menu btn from messagebox pressed")
                    MesiboCall.sharedInstance().call(parent, callid: 0, address: profile?.address, video: false, incoming: false)
                } else if item == 1 {
                    DispatchQueue.main.async(execute: {


                        MesiboCall.sharedInstance().call(parent, callid: 0, address: profile?.address, video: true, incoming: false)

                    })
                }
            }
            return true
        }
    }

In your view controller


    import UIKit


class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //Set user here

        let profile : MesiboUserProfile = MesiboUserProfile()
        profile.address = "youremail@email.com"
        MesiboUI.launchMessageViewController(self, profile: profile)

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM