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];
- Download SignalR-ObjC and try out the included Mac and iPhone example apps
- Install CocoaPods
- $ [sudo] gem install cocoapods
- $ pod setup
- cd SignalR-ObjC project directory
- $ pod install
- Install CocoaPods
- 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
- Install CocoaPods
- $ [sudo] gem install cocoapods
- $ pod setup
- 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' |
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. |
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];
//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);
}
SignalR-ObjC requires either iOS 5.0 and above, or Mac OS 10.7 (64-bit with modern Cocoa runtime) and above.
- SignalR-ObjC requires ARC
- SignalR-ObjC uses AFNetworking. The minimum supported version of AFNetworking is 1.0.0
- SignalR-ObjC uses SocketRocket. The minimum supported version of SocketRocket is 0.2.0
- SignalR-ObjC uses AnyJSON. The minimum supported version of AnyJSON is 0.0.1
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