Utility Methods API for PubNub Cocoa Objective-C SDK
The methods on this page are utility methods that don't fit into other categories.
Time
This function will return a 17 digit precision Unix epoch.
Algorithm constructing the timetoken
timetoken = (Unix epoch time in seconds) * 10000000
Example of creating a timetoken for a specific time and date:
08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000
Method(s)
To fetch Time
you can use the following method(s) in Cocoa SDK:
- (void)timeWithCompletion:(PNTimeCompletionBlock)block;
Parameter | Type | Required | Description |
---|---|---|---|
block | PNClientTimeTokenReceivingCompleteBlock | Yes | Time request process results handling block which pass two arguments: result - in case of successful request processing data field will contain server-provided timetoken; status - in case if error occurred during request processing |
Basic Usage
Get PubNub Timetoken
[self.client timeWithCompletion:^(PNTimeResult *result, PNErrorStatus *status) {
if (!status) {
// Handle downloaded server timetoken using: result.data.timetoken
}
else {
/**
Handle timetoken download 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];
show all 18 linesResponse
Response objects which is returned by client when Time API is used:
@interface PNTimeData : PNServiceData
// Current time on PubNub network servers.
@property (nonatomic, readonly, strong) NSNumber *timetoken;
@end
@interface PNTimeResult : PNResult
// Stores reference on time request processing information.
@property (nonatomic, readonly, strong) PNTimeData *data;
@end
Get size of message
This function provides a mechanism to calculate resulting message before it will be sent to the PubNub network.
Method(s)
To run Get size of message
you can use the following method(s) in the Cocoa SDK:
Get size of message with block
- (void)sizeOfMessage:(id)message
toChannel:(NSString *)channel
withCompletion:(PNMessageSizeCalculationCompletionBlock)block;
Parameter | Type | Required | Description |
---|---|---|---|
message | id | Yes | Message for which size should be calculated. |
channel | NSString | Yes | Name of the channel to which message should be sent (it is part of request URI). |
block | PNMessageSizeCalculationCompletionBlock | Yes | Reference on block which should be sent, when message size calculation will be completed. |
Get size of message with compression and block
- (void)sizeOfMessage:(id)message
toChannel:(NSString *)channel
compressed:(BOOL)compressMessage
withCompletion:(PNMessageSizeCalculationCompletionBlock)block;
Parameter | Type | Required | Description |
---|---|---|---|
message | id | Yes | Message for which size should be calculated. |
channel | NSString | Yes | Name of the channel to which message should be sent (it is part of request URI). |
compressMessage | Bool | Yes | YES in case if message should be compressed before sending to PubNub network. |
block | PNMessageSizeCalculationCompletionBlock | Yes | Reference on block which should be sent, when message size calculation will be completed. |
Get size of message with storage and block
- (void)sizeOfMessage:(id)message
toChannel:(NSString *)channel
storeInHistory:(BOOL)shouldStore
withCompletion:(PNMessageSizeCalculationCompletionBlock)block;
Parameter | Type | Required | Description |
---|---|---|---|
message | id | Yes | Message for which size should be calculated. |
channel | NSString | Yes | Name of the channel to which message should be sent (it is part of request URI). |
shouldStore | Bool | Yes | YES in case if message should be stored in Message Persistence. |
block | PNMessageSizeCalculationCompletionBlock | Yes | Reference on block which should be sent, when message size calculation will be completed. |
Get size of message with compression, storage, and block
- (void)sizeOfMessage:(id)message
toChannel:(NSString *)channel
compressed:(BOOL)compressMessage
storeInHistory:(BOOL)shouldStore
withCompletion:(PNMessageSizeCalculationCompletionBlock)block;
Parameter | Type | Required | Description |
---|---|---|---|
message | id | Yes | Message for which size should be calculated. |
channel | NSString | Yes | Name of the channel to which message should be sent (it is part of request URI). |
compressMessage | Bool | Yes | YES in case if message should be compressed before sending to PubNub network. |
shouldStore | Bool | Yes | NO in case if message shouldn't be available after it has been sent via history Message Persistence API methods group . |
block | PNMessageSizeCalculationCompletionBlock | Yes | Reference on block which should be sent, when message size calculation will be completed. |
Get size of message with metadata and block
- (void)sizeOfMessage:(id)message
toChannel:(NSString *)channel
withMetadata:(nullable NSDictionary<NSString *, id> *)metadata
completion:(PNMessageSizeCalculationCompletionBlock)block;
Parameter | Type | Required | Description |
---|---|---|---|
message | id | Yes | The message for which the size needs be calculated. |
channel | NSString | Yes | The channel on which the message has to be sent (it is part of request URI). |
metadata | NSDictionary | No | NSDictionary with values which should be used by PubNub service to filter messages. |
block | PNMessageSizeCalculationCompletionBlock | Yes | Completion block which will be called when the message size calculation is complete. |
Get size of message with compression, metadata, and block
- (void)sizeOfMessage:(id)message
toChannel:(NSString *)channel
compressed:(BOOL)compressMessage
withMetadata:(nullable NSDictionary<NSString *, id> *)metadata
completion:(PNMessageSizeCalculationCompletionBlock)block;
Parameter | Type | Required | Description |
---|---|---|---|
message | id | Yes | The message for which the size needs be calculated. |
channel | NSString | Yes | The channel on which the message has to be sent (it is part of request URI). |
compressMessage | Bool | Yes | Should be true if the message is compressed before sending to PubNub network. |
metadata | NSDictionary | No | NSDictionary with values which should be used by PubNub service to filter messages. |
block | PNMessageSizeCalculationCompletionBlock | Yes | Completion block which will be called when the message size calculation is complete. |
Get size of message with storage, metadata, and block
- (void)sizeOfMessage:(id)message
toChannel:(NSString *)channel
storeInHistory:(BOOL)shouldStore
withMetadata:(nullable NSDictionary<NSString *, id> *)metadata
completion:(PNMessageSizeCalculationCompletionBlock)block;
Parameter | Type | Required | Description |
---|---|---|---|
message | id | Yes | The message for which the size needs be calculated. |
channel | NSString | Yes | The channel on which the message has to be sent (it is part of request URI). |
shouldStore | Bool | Yes | Should be true if the message is marked to be stored in Message Persistence. |
metadata | NSDictionary | No | NSDictionary with values which should be used by PubNub service to filter messages. |
block | PNMessageSizeCalculationCompletionBlock | Yes | Completion block which will be called when the message size calculation is complete. |
Get size of message with storage, compression, metadata, and block
- (void)sizeOfMessage:(id)message
toChannel:(NSString *)channel
compressed:(BOOL)compressMessage
storeInHistory:(BOOL)shouldStore
withMetadata:(nullable NSDictionary<NSString *, id> *)metadata
completion:(PNMessageSizeCalculationCompletionBlock)block;
Parameter | Type | Required | Description |
---|---|---|---|
message | id | Yes | The message for which the size needs be calculated. |
channel | NSString | Yes | The channel on which the message has to be sent (it is part of request URI). |
shouldStore | Bool | Yes | Should be true if the message is marked to be stored in Message Persistence. |
compressMessage | Bool | Yes | Should be true if the message is compressed before sending to PubNub network. |
metadata | NSDictionary | No | NSDictionary with values which should be used by PubNub service to filter messages. |
block | PNMessageSizeCalculationCompletionBlock | Yes | Completion block which will be called when the message size calculation is complete. |
Basic Usage
Get message size
[self.client sizeOfMessage: @{@"Hello": @"world"} toChannel: @"announcement"
withCompletion:^(NSInteger size) {
// Process calculated target message size.
}];
Returns
The message size
Other Examples
Get size of message with metadata
[self.client sizeOfMessage: @{@"Hello": @"World"} toChannel: @"announcement"
withMetadata: @{@"senderID": @"bob"} completion:^(NSInteger size) {
// Process calculated target message size.
}];