Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift snippet using the authCallback. #470

Merged
merged 4 commits into from
Aug 29, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,31 @@ clientOptions.authCallback = { params, callback in
let client = ARTRealtime(options: clientOptions)
```

**Objective-C**

```objective-c
ARTClientOptions *clientOptions = [[ARTClientOptions alloc] init];
clientOptions.authCallback = ^(ARTTokenParams *params, void(^callBack)(id<ARTTokenDetailsCompatible>, NSError*)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this line on there's one extra level of indentation.

[self getTokenRequestJSONFromYourServer: params completion: ^(NSDictionary *json, NSError *error) {
//handle error
ARTTokenParams *tokenParams = [[ARTTokenParams alloc] initWithClientId: json[@"clientId"]];

ARTTokenRequest *tokenRequest = [[ARTTokenRequest alloc] initWithTokenParams: tokenParams
keyName: json[@"keyName"]
nonce: json[@"nonce"]
mac: json[@"mac"]];
tokenRequest.clientId = json[@"clientId"];
tokenRequest.ttl = [json[@"ttl"] doubleValue];
tokenRequest.capability = json[@"capability"];
tokenRequest.timestamp = [NSDate dateWithTimeIntervalSince1970: [json[@"timestamp"] doubleValue] / 1000];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't put a space between the : and the argument in other examples.


callBack(tokenRequest, nil);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called callback (all lower case) in all other examples.

}];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the closing param should be here, shouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but Xcode shows no warnings here, seems ok to me, what do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you're right, I parsed this wrong in my head.


ARTRealtime *client = [[ARTRealtime alloc] initWithOptions: clientOptions];
```

## Using the REST API

### Introduction
Expand Down