Skip to content

Commit

Permalink
Merge pull request #7 from thevixac/master
Browse files Browse the repository at this point in the history
code examples in the readme
  • Loading branch information
mattheworiordan committed Apr 20, 2015
2 parents 1b41dc9 + a549b5e commit be670f5
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 8 deletions.
96 changes: 89 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,99 @@ An iOS client library for [ably.io](https://www.ably.io), the realtime messaging
## Installation

* git clone https://github.com/ably/ably-ios
* drag ably-ios/ably-ios into your project as a group
* drag the directory ably-ios/ably-ios into your project as a group
* git clone https://github.com/square/SocketRocket.git
* drag SocketRocket/SocketRocket into your project as a group
* drag the directory SocketRocket/SocketRocket into your project as a group



## Using the Realtime API

### Connection
```
ARTRealtime * client = [[ARTRealtime alloc] initWithKey:@"xxxxx"];
[client subscribeToStateChanges:^(ARTRealtimeConnectionState state) {
if (state == ARTRealtimeConnected) {
// you are connected
}
}];
```

### Subscribing to a channel

```
ARTRealtimeChannel * channel = [client channel:@"test"];
[channel subscribe:^(ARTMessage * message) {
NSString * content =[message content];
NSLog(@" message is %@", content);
}];
```

### Publishing to a channel
```
[channel publish:@"Hello, Channel!" cb:^(ARTStatus status) {
if(status != ARTStatusOk) {
//something went wrong.
}
}];
```

### Querying the History
```
[channel history:^(ARTStatus status, id<ARTPaginatedResult> messagesPage) {
XCTAssertEqual(status, ARTStatusOk);
NSArray *messages = [messagesPage currentItems];
NSLog(@"this page has %d messages", [messages count]);
ARTMessage *message = messages[0];
NSString *messageContent = [message content];
NSLog(@"first item is %@", messageContent);
}];
```


### Presence on a channel
```
ARTOptions * options = [[ARTOptions alloc] initWithKey:@"xxxxx"];
options.clientId = @"john.doe";
ARTRealtime * client = [[ARTRealtime alloc] initWithOptions:options];
ARTRealtimeChannel * channel = [client channel:@"test"];
[channel publishPresenceEnter:@"I'm here" cb:^(ARTStatus status) {
if(status != ARTStatusOk) {
//something went wrong
}
}];
```

### Querying the Presence History
```
[channel presenceHistory:^(ARTStatus status, id<ARTPaginatedResult> presencePage) {
NSArray *messages = [presencePage currentItems];
if(messages) {
ARTPresenceMessage *firstMessage = messages[0];
NSString * content = [firstMessage content];
NSLog(@"first message is %@", content);
}
}];
```

## Using the REST API
```
ARTRest * client = [ARTRest alloc] initWithKey:@"xxxxx"];
ARTRestChannel * channel = [client channel:@"test"];
```

## Publishing a message to a channel
```
[channel publish:@"Hello, channel!" cb:^(ARTStatus status){
if(status != ARTStatusOk) {
//something went wrong
}
}];
```

## Dependencies

The library works on iOS7 and above, and uses [SocketRocket](https://github.com/square/SocketRocket)

## Usage

See https://www.ably.io/documentation for a quickstart guide
The library works on iOS8, and uses [SocketRocket](https://github.com/square/SocketRocket)

## Known limitations

Expand Down
6 changes: 5 additions & 1 deletion ably-iosTests/ARTRealtimeResumeTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ -(void) testSimple
}
}];
__block bool firstRecieved = false;
__block bool rec = false; //TODO work out why this gets called twice. rm rec
[channel subscribe:^(ARTMessage * message) {
if([[message content] isEqualToString:message1]) {
firstRecieved = true;
Expand All @@ -120,7 +121,10 @@ -(void) testSimple
else if([[message content] isEqualToString:message4]) {
XCTAssertTrue(firstRecieved);
XCTAssertTrue(disconnects>0);
[expectation fulfill];
if(!rec) {
rec =true;
[expectation fulfill];
}
}
}];

Expand Down

0 comments on commit be670f5

Please sign in to comment.