adamhartford / SwiftR

Swift client for SignalR (iOS and Mac)
MIT License
174 stars 74 forks source link

"There was an error invoking Hub" Swift 4 #109

Open munsifhayat opened 6 years ago

munsifhayat commented 6 years ago

Hi everyone ! I am really stuck into this issue. I am passing these arguments:

let message = ["feedbackId": 79, "chatText": "Complex Test", "toId": "4b556216-20ca-4338-b055-6f8dbbaee5ff", "fromId":userGuidID] as [String : Any]

            print(message)

            do {
                if let invokingHub = simpleHub {

                    try invokingHub.invoke("SendInstantMessage", arguments: [message]) { (result, error) in

                        if let e = error {

                            print("Error: \(e)")

                        } else {
                            print("Success!")
                            if let r = result {
                                print("Result: \(r)")

                                DispatchQueue.main.async {
                                    let message =  self.chatWindow?.sendText(text, isIncomingMessage: false)
                                    self.chatWindow?.addMessageToMessenger(message!)
                                }
                            }
                        }
                    }
                }

            } catch {
                //handle error
                print(error)
            }

My Arguments Output : This I am sending to server. Which is same as my Android fellow. I am receiving messages but not able to send.

{"chatText":"Complex Test","toId":"4b556216-20ca-4338-b055-6f8dbbaee5ff","feedbackId":80,"fromId":"67aaffb6-e403-4fcc-a208-fdec55bcc1f4"}

SentoCrespo commented 6 years ago

Any news? I can only receive messages but cannot invoke anything on the server. Even the callback does NOT get called...

Ivce tried with a simpler message, only invoke a method, no parameters.

Using Swift 4, Xcode 9.2, Pods

Any help or workaround in here?

SentoCrespo commented 6 years ago

More information: useWKWebview is not set to true (so it's false).

This is quite annoying and frustrating.

Any advise guys? Thanks.

adamhartford commented 6 years ago

Would someone be able to share an example project that demonstrates the issue, or show how it can happen using the Demo application?

SentoCrespo commented 6 years ago

I'm afraid I can't do that. If I set the option useWKWebview = true

Then the connection fails, so I guess the server doesn't have Cors enabled as the readme states.

SignalR version is 2.2.2 though.

munsifhayat commented 6 years ago

Its working great on my side now. Here are my findings : -> Enable CORS at your backend side. -> Look into your modal that you are passing. if not solved than look again to your modal.

Here is my modal and the way it worked for me.

    let m = "{\"chatText\":\"\(chatText)\",\"todIdList\":\(toSendIds),\"feedbackId\":\(feedbackId),\"messageTextType\":1001,\"fromId\":\"\(userGuid)\"}"

    do {
        if let invokingHub = simpleHubVendor {

            try invokingHub.invoke("SendInstantMessage", arguments: [m]) { (result, error) in

                if let e = error {
                    print("Error: \(e)")
                } else {
                    print("Success!")
                    if let r = result {
                        print("Result: \(r)")

                    }
                }
            }
        }