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

invoke server method,how get return value,eg string #11

Closed
MakerXia opened this issue Oct 14, 2015 · 6 comments
Closed

invoke server method,how get return value,eg string #11

MakerXia opened this issue Oct 14, 2015 · 6 comments

Comments

@MakerXia
Copy link

invoke server method,how get return value,eg string,thank you
public string SendComplex(ComplexMessage message) {

  Clients.All.notifyComplex (message);
  return "OK"

}

@adamhartford
Copy link
Owner

Hi, I'll need some more information to help. Can you post some of your client code? In general, you should have something like this:

SwiftR.connect("http://yourserver.com") { connection in
    self?.complexHub = connection.createHubProxy("complexHub")

    self?.complexHub.on("notifyComplex") { args in
        let m: AnyObject = args!["0"] as AnyObject!
        print(m)
    }
}

@MakerXia
Copy link
Author

I need some method like SignalR-objc method,like below code
renderHub?.invoke("hello", withArgs: renderArgs, completionHandler: { (response, error) -> Void in
print("(response)")
})
thank you

@adamhartford
Copy link
Owner

OK, I see. I haven't added support for invoke return values yet. I agree that this would be nice to have. I'll work on it next.

@adamhartford
Copy link
Owner

Commit fb4fdce adds this support. The invoke signature is now:

public func invoke(method: String, arguments: [AnyObject]?, callback: ((AnyObject?, String?) -> ())? = nil)

Here's an example usage:

simpleHub.invoke("sendSimple", arguments: ["Simple Test", "This is a simple message"]) { (result, error) in
    if let e = error {
        print("Error message: \(e)")
    } else {
        print("Success!")
        if let r = result {
            print("Result: \(r)")
        }
    }
}

@MakerXia
Copy link
Author

Thank you!

@adamhartford
Copy link
Owner

Change is included in v0.8.1.

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

2 participants