Skip to content

Objective-C Client for the SignalR Project works with iOS and Mac

License

Notifications You must be signed in to change notification settings

noamberda/SignalR-ObjC

 
 

Repository files navigation

SignalR-ObjC is a client library for iOS and Mac OS X. It's built on top of two popular open source libraries AFNetworking and SocketRocket. SignalR-ObjC is intended to be used along side ASP.NET SignalR, a new library for ASP.NET developers that makes it incredibly simple to add real-time functionality to your applications. What is "real-time web" functionality? It's the ability to have your server-side code push content to the connected clients as it happens, in real-time.

For example, here's how easy it is to get started:

SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite/echo"];
connection.received = ^(NSString * data) {
    NSLog(data);
};
connection.started =  ^{
    [connection send:@"hello world"];
};
[connection start];

How To Get Started

  • Download SignalR-ObjC and try out the included Mac and iPhone example apps
    1. Install CocoaPods
      • $ [sudo] gem install cocoapods
      • $ pod setup
    2. cd SignalR-ObjC project directory
    3. $ pod install
  • Check out the documentation for a comprehensive look at the APIs available in SignalR-ObjC. NOTE: this is a work in progress and is currently outdated.
  • Questions? JabbR is the best place to find answers

Installation

  1. Install CocoaPods
    • $ [sudo] gem install cocoapods
    • $ pod setup
  2. Create or Add SignalR to your "Podfile"
Sample iOS Podfile Sample OSX Podfile
platform :ios, '5.0'
pod 'SignalR-ObjC'
platform :osx, '10.7'
pod 'SignalR-ObjC'
3. Install SignalR-ObjC into your project * $ pod install

Overview

Hubs
SRHubConnection
Core
SRConnection
Transports
SRAutoTransport SRAutoTransport chooses the best supported transport for both client and server. This achieved by falling back to less performant transports.
The default transport fallback is:
1. SRWebSocketTransport
2. SRServerSentEventsTransport
3. SRLongPollingTransport
SRWebSocketsTransport WebSockets is the only transport that establishes a true persistent, two-way connection between the client and server.
SRServerSentEventsTransport With Server Sent Events, also known as EventSource, it's possible for a server to send new data to a client at any time, by pushing messages to the client. Server Sent Events requires few new connections then Long Polling and therefore will have less latency.
SRLongPollingTransport Long polling does not create a persistent connection, but instead polls the server with a request that stays open until the server responds, at which point the connection closes, and a new connection is requested immediately. This may introduce some latency while the connection resets.

Example Usage

Persistent Connection

using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;

//Server
public class MyConnection : PersistentConnection 
{
    protected override Task OnReceived(IRequest request, string connectionId, string data) 
    {
        // Broadcast data to all clients
        return Connection.Broadcast(data);
    }
}
#import "SignalR.h"

//Client
SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite/echo"];
connection.received = ^(NSString * data) {
    NSLog(data);
};
connection.started =  ^{
    [connection send:@"hello world"];
};
[connection start];

Hubs

//Server
public class Chat : Hub 
{
    public void Send(string message)
    {
        // Call the addMessage method on all clients            
        Clients.All.addMessage(message);
    }
}
//Client
#import "SignalR.h"

// Connect to the service
SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://localhost/mysite"];
// Create a proxy to the chat service
SRHubProxy *chat = [hubConnection createHubProxy:@"chat"];
[chat on:@"addMessage" perform:self selector:@selector(addMessage:)];
// Start the connection
[hubConnection start];

- (void)addMessage:(NSString *)message {
    // Print the message when it comes in
    NSLog(message);
}

Requirements

SignalR-ObjC requires either iOS 6.0 and above, or Mac OS 10.8 (64-bit with modern Cocoa runtime) and above.

ARC

  • SignalR-ObjC requires ARC

Networking

  • SignalR-ObjC uses AFNetworking. The minimum supported version of AFNetworking is 2.0.0
  • SignalR-ObjC uses SocketRocket. The minimum supported version of SocketRocket is 0.2.0

LICENSE

SignalR-ObjC is available under the MIT license. See the LICENSE file for more info.
SignalR-ObjC uses 3rd-party code which each have specific licenses, see ACKNOWLEDGEMENTS for contributions

About

Objective-C Client for the SignalR Project works with iOS and Mac

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 96.8%
  • C 2.8%
  • Ruby 0.4%