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

please help me about "Received method" #29

Open
rockmanlhu opened this issue Feb 23, 2016 · 5 comments
Open

please help me about "Received method" #29

rockmanlhu opened this issue Feb 23, 2016 · 5 comments

Comments

@rockmanlhu
Copy link

i have a problem with method receive message from server
i don't know why i alway received the msg like that: "{
A = (
);
H = ChatHub;
M = onUserDisconnected;
}"
help me!!!

@adamhartford
Copy link
Owner

Hi, are you saying you're able to call a method on your server, but have a problem when the server tries to send a message to your client?

Do you have any code to share?

@rockmanlhu
Copy link
Author

when i set SwiftR.useWKWebView = true
i receive messages: "Starting...

Error: Optional({

  • column = 4521;*
  • context = {*
  •    readyState = 0;*
    
  •    status = 0;*
    
  •    statusText = error;*
    
  • };*
  • errorMessage = "Error during negotiation request.";*
  • line = 8;*
  • source = {*
  •    readyState = 0;*
    
  •    status = 0;*
    
  •    statusText = error;*
    
  • };*
  • sourceURL =
    "file:///var/mobile/Containers/Bundle/Application/989279A0-AFE8-4A4C-B2F5-B389B678BEC4/SwiftR%20iOS%20Demo.app/Frameworks/SwiftR.framework/jquery.signalR-2.2.0.min.js";*

})

Disconnected."

Please help me!!!

On Wed, Feb 24, 2016 at 12:58 AM, Adam Hartford [email protected]
wrote:

Hi, are you saying you're able to call a method on your server, but have a
problem when the server tries to send a message to your client?

Do you have any code to share?


Reply to this email directly or view it on GitHub
#29 (comment).

@adamhartford
Copy link
Owner

If it works with UIWebView, but not WKWebView, it could be that you haven't enabled CORS for your SignalR server.

If not, I'll need to know what version of SignalR you're using and if you're able to use your server with a plain JavaScript or other client, to prove that the server is working.

@AltafRehman
Copy link

Hi Adamhartford,

I am having the same issue. In my case server is working fine because when I use signalR it works but having an issue of hubProxy callbacks methods not getting invoke thats why I switched to swiftR.
Unfortunately this is not getting me connect.
Here is my code

SwiftR.useWKWebView = true

    // Default is .Auto
    SwiftR.transport = .ServerSentEvents

    // Hubs...
    hubConnection = SwiftR.connect("http://qa.mrpg.net/apis/mrpempower/signalr") { [weak self] connection in

        connection.queryString = ["clientProtocol" : "1.5", "Bearer":self!.token , "connectionData":[["name":"socialhub"]]]

        connection.headers = ["Accept-Encoding": "gzip, deflate, sdch", "Accept-Language": "en-US", "Content-Type":"Application/x-www-form-urlencoded"]

        self?.simpleHub = connection.createHubProxy("socialhub")

        self?.simpleHub.on("Connect1Callback", parameters: ["response"]) { args in
            let response = args!["response"] as! String
            print("Message: \(response)\n")
        }

        // SignalR events

        connection.starting = { [weak self] in
            print("Starting...")
        }

        connection.reconnecting = { [weak self] in
            print("Reconnecting...")
        }

        connection.connected = { [weak self] in
            print("Connected. Connection ID: \(connection.connectionID!)")
        }

        connection.reconnected = { [weak self] in
            print("Reconnected. Connection ID: \(connection.connectionID!)")
        }

        connection.disconnected = { [weak self] in
            print("Disconnected.")
        }

        connection.connectionSlow = { print("Connection slow...") }

        connection.error = {
            error in print("Error: \(error)")

            // Here's an example of how to automatically reconnect after a timeout.
            //
            // For example, on the device, if the app is in the background long enough
            // for the SignalR connection to time out, you'll get disconnected/error
            // notifications when the app becomes active again.

            if let source = error?["source"] as? String where source == "TimeoutException" {
                print("Connection timed out. Restarting...")
                connection.start()
            }
        }
    }

@rockmanlhu
Copy link
Author

Hi Adamhartford,
Can you help me about "Receive event"
I alway received a message: "Optional({

  • A = (*
  • );*
  • H = ChatHub;*
  • M = onUserDisconnected;*

})

while anothers send a msg to me
Thanks!

On Mon, Feb 29, 2016 at 8:17 PM, AltafRehman [email protected]
wrote:

Hi Adamhartford,

I am having the same issue. In my case server is working fine because when
I use signalR it works but having an issue of hubProxy callbacks methods
not getting invoke thats why I switched to swiftR.
Unfortunately this is not getting me connect.
Here is my code

SwiftR.useWKWebView = true

// Default is .Auto
SwiftR.transport = .ServerSentEvents

// Hubs...
hubConnection = SwiftR.connect("http://qa.mrpg.net/apis/mrpempower/signalr") { [weak self] connection in

    connection.queryString = ["clientProtocol" : "1.5", "Bearer":self!.token , "connectionData":[["name":"socialhub"]]]

    connection.headers = ["Accept-Encoding": "gzip, deflate, sdch", "Accept-Language": "en-US", "Content-Type":"Application/x-www-form-urlencoded"]

    self?.simpleHub = connection.createHubProxy("socialhub")

    self?.simpleHub.on("Connect1Callback", parameters: ["response"]) { args in
        let response = args!["response"] as! String
        print("Message: \(response)\n")
    }

    // SignalR events

    connection.starting = { [weak self] in
        print("Starting...")
    }

    connection.reconnecting = { [weak self] in
        print("Reconnecting...")
    }

    connection.connected = { [weak self] in
        print("Connected. Connection ID: \(connection.connectionID!)")
    }

    connection.reconnected = { [weak self] in
        print("Reconnected. Connection ID: \(connection.connectionID!)")
    }

    connection.disconnected = { [weak self] in
        print("Disconnected.")
    }

    connection.connectionSlow = { print("Connection slow...") }

    connection.error = {
        error in print("Error: \(error)")

        // Here's an example of how to automatically reconnect after a timeout.
        //
        // For example, on the device, if the app is in the background long enough
        // for the SignalR connection to time out, you'll get disconnected/error
        // notifications when the app becomes active again.

        if let source = error?["source"] as? String where source == "TimeoutException" {
            print("Connection timed out. Restarting...")
            connection.start()
        }
    }
}


Reply to this email directly or view it on GitHub
#29 (comment).

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