Giter Club home page Giter Club logo

signalr-client-swift's Introduction

SwiftSignalRClient

A Swift SignalR Client for the Asp.Net Core version of SignalR

Before filing an issue please check Frequently Asked Questions

Installation

Cocoapods

Add the following lines to your Podfile:

use_frameworks!
pod 'SwiftSignalRClient'

Then run:

pod install

Swift Package Manager

The easiest way to is to use Use XCode UI (File -> Add Packages...)

Alternatively, add the following to your Package dependencies:

.package(url: "https://github.com/moozzyk/SignalR-Client-Swift", .upToNextMinor(from: "0.9.0")),

Then include "SignalRClient" in your target dependencies. For example:

.target(name: "MySwiftPackage", dependencies: ["SignalRClient"]),

Carthage

Add the following lines to your Cartfile:

github "moozzyk/SignalR-Client-Swift"

Then run:

carthage update

Usage

Add import SwiftSignalRClient (or import SignalRClient if you are using Swift Package Manager) to swift files you would like to use the client in.

A typical implementation looks like the following:

import Foundation
import SwiftSignalRClient

public class SignalRService {
    private var connection: HubConnection
    
    public init(url: URL) {
        connection = HubConnectionBuilder(url: url).withLogging(minLogLevel: .error).build()
        connection.on(method: "MessageReceived", callback: { (user: String, message: String) in
            do {
                self.handleMessage(message, from: user)
            } catch {
                print(error)
            }
        })
        
        connection.start()
    }
    
    private func handleMessage(_ message: String, from user: String) {
        // Do something with the message.
    }
}

More detailed user's guide:

Examples

There are several sample projects in the Examples folder. They include:

  • SignalRClient.xcodeproj

    An Xcode workspace that has compiled libraries for macOS (OSX) and iOS, along with the Application targets 'ConnectionSample', 'HubSample', and 'HubSamplePhone'.

  • TestServer

    A .Net solution that the unit tests and samples can be run against.

    The TestServer Requires .NET Core SDK 3.0.100 or later.

    To run, navigate to the TestServer folder and execute the following in the terminal:

    % npm install
    % dotnet run

    When running the TestServer project on macOS Monterey (12.0 or greater), you may encounter the error: "Failed to bind to address http://0.0.0.0:5000: address already in use.". This is due to Apple now advertising an 'AirPlay Receiver' on that port. This port can be freed by disabling the receiver: Navigate to System Preferences > Sharing and uncheck AirPlay Receiver.

Disclaimer

I am providing code in the repository to you under an open source license. Because this is my personal repository, the license you receive to my code is from me and not my employer (Facebook)

Hits

HitCount

signalr-client-swift's People

Contributors

moozzyk avatar richardpiazza avatar mattgallagher avatar brentatresultstack avatar dependabot[bot] avatar abakhtin avatar ninban avatar davidjrobertson avatar dkornev avatar gpotari avatar imjamper avatar guillermociquecom avatar katexe avatar maxim-kiselev avatar wacumov avatar miranl avatar mythicbits avatar ovidiuadorian-yonder avatar andre-alves avatar joshr604 avatar kenrf avatar mattspark170 avatar trykovyura avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.