adamhartford / SwiftR

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

SwiftR + Xcode 9 #96

Closed dyountmusic closed 3 years ago

dyountmusic commented 7 years ago

Seems to be some breaking changes with the way SwiftR is compiling inside of Xcode 9 for the latest version of this master branch?

Anybody else experiencing something similar?

jsembdner commented 7 years ago

Have you tried Xcode 9 GM? Working fine for me with cocoapods.

dyountmusic commented 7 years ago

Yeah, running Xcode 9 GM. Xcode compiler is telling me that the SwiftR.connect() method is missing a parameter of <#UnsafePointer<sockaddr>!#> so it looks like it's not actually attempting to call the appropriate method. It almost seems like all references to just SwiftR.something() has broken. Another method call in my codebase of SwiftR.stopAll() has also broken.

Will post an update if I can get it working.

ayman-karram commented 6 years ago

@dyountmusic did you make this run?

adamhartford commented 6 years ago

I haven't seen this problem before. Would someone being willing to post an example project that demonstrates the issue?

ayman-karram commented 6 years ago

SignalRSample.zip @adamhartford check this example

adamhartford commented 6 years ago

I see. This example hasn't been updated since the SwiftR API changed. The SwifR.* functions aren't used anymore as of v0.13.0. From the release note:

You now create a SignalR instance instead of using SwiftR.connect(). This is intended to make the setup code easier to read and understand, and allows the connection setup to be done outside of callback (a common question/complaint).

If you do not want to update your code for these changes, point your SwiftR Podfile reference to version 0.12.0.

The correct syntax for v0.13.0 and higher is in the README and the demo project.

For example, from the demo project:

var chatHub: Hub!
var connection: SignalR!
var name: String!

override func viewDidLoad() {
    super.viewDidLoad()

    connection = SignalR("http://swiftr.azurewebsites.net")
    connection.useWKWebView = true
    connection.signalRVersion = .v2_2_0

    chatHub = Hub("chatHub")
    chatHub.on("broadcastMessage") { [weak self] args in
        if let name = args?[0] as? String, let message = args?[1] as? String, let text = self?.chatTextView.text {
            self?.chatTextView.text = "\(text)\n\n\(name): \(message)"
        }
    }
    connection.addHub(chatHub)

        // SignalR events

    connection.starting = { [weak self] in
        self?.statusLabel.text = "Starting..."
        self?.startButton.isEnabled = false
        self?.sendButton.isEnabled = false
    }

    connection.reconnecting = { [weak self] in
        self?.statusLabel.text = "Reconnecting..."
        self?.startButton.isEnabled = false
        self?.sendButton.isEnabled = false
    }

    connection.connected = { [weak self] in
        print("Connection ID: \(self!.connection.connectionID!)")
        self?.statusLabel.text = "Connected"
        self?.startButton.isEnabled = true
        self?.startButton.title = "Stop"
        self?.sendButton.isEnabled = true
    }

    connection.reconnected = { [weak self] in
        self?.statusLabel.text = "Reconnected. Connection ID: \(self!.connection.connectionID!)"
        self?.startButton.isEnabled = true
        self?.startButton.title = "Stop"
        self?.sendButton.isEnabled = true
    }

    connection.disconnected = { [weak self] in
        self?.statusLabel.text = "Disconnected"
        self?.startButton.isEnabled = true
        self?.startButton.title = "Start"
        self?.sendButton.isEnabled = false
    }

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

    connection.error = { [weak self] error in
        print("Error: \(String(describing: 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, source == "TimeoutException" {
            print("Connection timed out. Restarting...")
            self?.connection.start()
        }
    }

    connection.start()
}