Latest | 0.5.0 |
---|---|
Homepage | https://github.com/moozzyk/SignalR-Client-Swift |
License | Attribution License |
Platforms | ios 9.0, osx 10.13, tvos 9.0, requires ARC |
Authors |
A Swift SignalR Client for the Asp.Net Core version of SignalR
Installation
Cocoapods
Add the following lines to your Podfile
:
use_frameworks!
pod 'SwiftSignalRClient'
Then run:
pod install
Swift Packacge Manager
Add the following to your Package
dependencies:
.package(url: "https://github.com/moozzyk/SignalR-Client-Swift", .upToNextMinor(from: "0.5.0")),
Then include "SignalRClient"
in your target dependencies. For example:
.target(name: "MySwiftPackage", dependencies: ["SignalRClient"]),
Usage
Add import SignalRClient
to swift files you would like to use the client in.
A typical implementation looks like the following:
import Foundation
import SignalRClient
public class SignalRService {
private var connection: HubConnection
public init(url: URL) {
connection = HubConnectionBuilder(url: url).withLogging(minLogLevel: .error).build()
connection.on(method: "MessageReceived", callback: { (args, typeConverter) in
do {
let user = try typeConverter.convertFromWireType(obj: args[0], targetType: String.self)
let message = try typeConverter.convertFromWireType(obj: args[1], targetType: String.self)
self.handleMessage(message, from: user)
} catch {
print(error)
}
})
connection.start()
}
private func handleMessage(_ message: String, from user: String) {
// Do something with the message.
}
}
Examples
There are several sample projects in the Examples
folder. They include:
-
An Xcode workspace that has compiled libraries for macOS (OSX) and iOS, along with the Application targets ‘ConnectionSample’, ‘HubSample’, and ‘HubSamplePhone’.
-
A .Net solution that the unit tests can be run against.
The
TestServer
Requires .NET Core SDK 2.1.300 or later.To run, navigate to the
TestServer
folder and execute the following in the terminal:npm install
“`C#
dotnet run
Latest podspec
{ "name": "SwiftSignalRClient", "version": "0.5.0", "summary": "Swift SignalR Client for the ASP.Net Core version of SignalR.", "homepage": "https://github.com/moozzyk/SignalR-Client-Swift", "license": { "type": "Attribution License", "file": "LICENSE" }, "source": { "git": "https://github.com/moozzyk/SignalR-Client-Swift.git", "tag": "0.5.0" }, "authors": { "Pawel Kadluczka": "[email protected]" }, "social_media_url": "https://twitter.com/moozzyk", "swift_version": "5.0", "platforms": { "ios": "9.0", "osx": "10.13", "tvos": "9.0" }, "source_files": "Sources/SignalRClient/*.swift", "requires_arc": true, "libraries": "z" }
Fri, 10 May 2019 10:55:08 +0000