Created
December 2, 2016 07:41
-
-
Save d0z0/a3e69e5d20d8262265e8db72acaf865e to your computer and use it in GitHub Desktop.
iOS Pubnub code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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