Swift中的信号R

时间:2016-12-15 10:55:02

标签: ios swift signalr swiftr

嗨,我想在我的聊天应用程序中实现一个swiftR。我遵循了tutorial

Iam不断收到此错误

  

开始......

Error: Optional(["message": Error during negotiation request.]) 

Disconnected.

这是我的Swift代码。

import UIKit
import SwiftR


class FirstViewController: UIViewController {


    var simpleHub: Hub!
    var complexHub: Hub!

    var hubConnection: SignalR!
    var persistentConnection: SignalR!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Make sure myserver.com is mapped to 127.0.0.1 in /etc/hosts
        // Or change myserver.com to localhost or IP below

        // Default is false
        SwiftR.useWKWebView = true



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

        // Hubs...
        hubConnection = SwiftR.connect("https://MYHUBURL HERE/") { [weak self] connection in


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


            SwiftR.startAll();


            // SignalR events

            connection.starting = {
                print("Starting...")
            }

            connection.reconnecting = {
                print("Reconnecting...")
            }

            connection.connected = {
                print("Connected. Connection ID: \(connection.connectionID!)")

            }

            connection.reconnected = {
                print("Reconnected. Connection ID: \(connection.connectionID!)")
            }

            connection.disconnected = {
                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 , source == "TimeoutException" {
                    print("Connection timed out. Restarting...")
                    connection.start()
                }
            }
        }

        // Persistent connection...
        // Uncomment when using persitent connections on your SignalR server
        //        persistentConnection = SwiftR.connect("http://myserver.com:5000/echo", connectionType: .persistent) { connection in
        //            connection.received = { data in
        //                print(data!)
        //            }
        //        }

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

有人可以帮助我连接到signR。

在github上:https://github.com/adamhartford/SwiftR/issues/75

0 个答案:

没有答案