Skip to content

Instantly share code, notes, and snippets.

@d0z0
Created December 2, 2016 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d0z0/a3e69e5d20d8262265e8db72acaf865e to your computer and use it in GitHub Desktop.
Save d0z0/a3e69e5d20d8262265e8db72acaf865e to your computer and use it in GitHub Desktop.
iOS Pubnub code
- (void)doPubNubTest {
[self.client publish: @"Hello from PubNub iOS!" toChannel: @"dummy_ios_channel" storeInHistory:YES
withCompletion:^(PNPublishStatus *status) {
if (!status.isError) {
initialTime = [[NSDate date] timeIntervalSince1970];
// Message successfully published to specified channel.
}
else {
/**
Handle message publish error. Check 'category' property to find
out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
Request can be resent using: [status retry];
*/
}
}];
}
// Handle new message from one of channels on which client has been subscribed.
- (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {
// Handle new message stored in message.data.message
if (![message.data.channel isEqualToString:message.data.subscription]) {
// Message has been received on channel group stored in message.data.subscription.
}
else {
// Message has been received on channel stored in message.data.channel.
}
double laterTime = [[NSDate date] timeIntervalSince1970];
NSLog(@"sent at -> %f", initialTime);
NSLog(@"received at -> %f", laterTime);
NSLog(@"%f", (laterTime - initialTime)*1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment