Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hub.on is not getting called in Swift 4 :( #103

Open
rajeevfp opened this issue Dec 22, 2017 · 4 comments
Open

Hub.on is not getting called in Swift 4 :( #103

rajeevfp opened this issue Dec 22, 2017 · 4 comments

Comments

@rajeevfp
Copy link

rajeevfp commented Dec 22, 2017

Hi I'm using SwiftR (0.14.0) in swift 4 Xcode 9 . The following connecting to server but hub.on is not getting called where i need to get response. Please help me to resolve this. Thanks

        hubConnection = SignalR("http://chat.friends.com/")
        hubConnection.useWKWebView = false
        let bearerKey = UserDefaults.standard.string(forKey: "BearerKey")! as NSString
        hubConnection?.headers = ["Authorization": "Bearer "+(bearerKey as String)]
        
        simpleHub = Hub("MobileChatHub")
        complexHub = Hub("MobileChatHub")
        
        hubConnection.addHub(simpleHub)
        hubConnection.addHub(complexHub)
        
        simpleHub.on("ChatContactsResponse") { args in
            let message = args![0] as! String
            let detail = args![1] as! String
            print("Message: \(message)\nDetail: \(detail)\n")
        }
        
        complexHub.on("ChatContactsResponse") { args in
            let m: AnyObject = args![0] as AnyObject!
            print(m)
        }
        
        // SignalR events
        
        hubConnection.starting = { [weak self] in
            print("Starting...")
        }
        
        hubConnection.reconnecting = { [weak self] in
            print("Reconnecting...")
           
        }
        
        hubConnection.connected = { [weak self] in
            print("Connected. Connection ID: \(String(describing: self!.hubConnection.connectionID))")
            do {
                try self?.simpleHub.invoke("GetChatContacts", arguments: [false])
            } catch {
                print(error)
            }
        }
        
        hubConnection.reconnected = { [weak self] in
            print("Reconnected. Connection ID: \(String(describing: self!.hubConnection.connectionID))")
            
        }
        
        hubConnection.disconnected = { [weak self] in
            print("Disconnected.")
        }
        
        hubConnection.connectionSlow = { print("Connection slow...") }
        
        hubConnection.error = { [weak self] error in
            print("Error: \(String(describing: error))")
       
            if let source = error?["source"] as? String , source == "TimeoutException" {
                print("Connection timed out. Restarting...")
                self?.hubConnection.start()
            }
        }
        
        hubConnection.start()
@rajeevfp rajeevfp changed the title Hub.on never gets called in Swift 4 :( Hub.on is not getting called in Swift 4 :( Dec 22, 2017
@cavoixanha
Copy link

Have you found a solution?

@munsifhayat
Copy link

Any solution ?

@cavoixanha
Copy link

cavoixanha commented Mar 8, 2018

Can server only send complexHub.on("event") to connectionId register, should you can't catch this event! Before I also faulty this! Fix by use hub.invoke('connect', username);

@munsifhayat
Copy link

For me its working pretty clean now. I think their is no issues in case of swift 4 and xCode 9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants