CocoaCocoaiOSObjective-CCocoa Misc API Reference for Realtime Apps

Go to Objects (BETA)


This function will return a 17 digit precision Unix epoch.
 
Timetoken
The timetoken is constructed using the following algorithm:
timetoken = (Unix epoch time in seconds) * 10000000
Example of creating a timetoken for a specific time & date
08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000
To fetch Time you can use the following method(s) in Objective-C SDK
  1. ParameterTypeRequiredDescription
    blockPNClientTimeTokenReceivingCompleteBlockYesTime request process results handling block which pass two arguments: result - in case of successful request processing data field will contain server-provided time token; status - in case if error occurred during request processing
[self.client timeWithCompletion:^(PNTimeResult *result, PNErrorStatus *status) {

	if (!status) {

		// Handle downloaded server time token using: result.data.timetoken
	}
	else {

		/**
		 Handle time token 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];
		 */
	}
}];
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
This function provides a mechanism to calculate resulting message before it will be sent to the PubNub network.
To run Get size of message you can use the following method(s) in the Objective-C SDK
  1. ParameterTypeRequiredDescription
    messageidYesMessage for which size should be calculated.
    channelNSStringYesName of the channel to which message should be sent (it is part of request URI).
    blockPNMessageSizeCalculationCompletionBlockYesReferecnce on block which should be sent, when message size calculation will be completed.
  2. ParameterTypeRequiredDescription
    messageidYesMessage for which size should be calculated.
    channelNSStringYesName of the channel to which message should be sent (it is part of request URI).
    compressMessageBoolYesYES in case if message should be compressed before sending to PubNub network.
    blockPNMessageSizeCalculationCompletionBlockYesReferecnce on block which should be sent, when message size calculation will be completed.
  3. ParameterTypeRequiredDescription
    messageidYesMessage for which size should be calculated.
    channelNSStringYesName of the channel to which message should be sent (it is part of request URI).
    shouldStoreBoolYesYES in case if message should beplaced into history storage.
    blockPNMessageSizeCalculationCompletionBlockYesReferecnce on block which should be sent, when message size calculation will be completed.
  4. ParameterTypeRequiredDescription
    messageidYesMessage for which size should be calculated.
    channelNSStringYesName of the channel to which message should be sent (it is part of request URI).
    compressMessageBoolYesYES in case if message should be compressed before sending to PubNub network.
    shouldStoreBoolYesNO in case if message shouldn't be available after it has been sent via history storage API methods group.
    blockPNMessageSizeCalculationCompletionBlockYesReferecnce on block which should be sent, when message size calculation will be completed.
  5. ParameterTypeRequiredDescription
    messageidYesThe message for which the size needs be calculated.
    channelNSStringYesThe channel on which the message has to be sent (it is part of request URI).
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNMessageSizeCalculationCompletionBlockYesCompletion block which will be called when the message size calculation is complete.
  6. ParameterTypeRequiredDescription
    messageidYesThe message for which the size needs be calculated.
    channelNSStringYesThe channel on which the message has to be sent (it is part of request URI).
    compressMessageBoolYesShould be true if the message is compressed before sending to PubNub network.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNMessageSizeCalculationCompletionBlockYesCompletion block which will be called when the message size calculation is complete.
  7. ParameterTypeRequiredDescription
    messageidYesThe message for which the size needs be calculated.
    channelNSStringYesThe channel on which the message has to be sent (it is part of request URI).
    shouldStoreBoolYesShould be true if the message is marked to be stored in history.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNMessageSizeCalculationCompletionBlockYesCompletion block which will be called when the message size calculation is complete.
  8. ParameterTypeRequiredDescription
    messageidYesThe message for which the size needs be calculated.
    channelNSStringYesThe channel on which the message has to be sent (it is part of request URI).
    shouldStoreBoolYesShould be true if the message is marked to be stored in history.
    compressMessageBoolYesShould be true if the message is compressed before sending to PubNub network.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNMessageSizeCalculationCompletionBlockYesCompletion block which will be called when the message size calculation is complete.
 [self.client sizeOfMessage: @{@"Hello": @"world"} toChannel: @"announcement"
			 withCompletion:^(NSInteger size) {
 
	// Process calculated target message size.
 }];
The message size
  1. [self.client sizeOfMessage: @{@"Hello": @"World"} toChannel: @"announcement"
    			  withMetadata: @{@"senderID": @"bob"} completion:^(NSInteger size) {
    
    	// Process calculated target message size.
    }];
This function allow to encrypt the data.
To encrypt the data you can use the following method(s) in Objective-C SDK.
  1. ParameterTypeRequiredDescription
    dataNSDataYesReference on NSData object which should be encrypted.
    keyNSStringYesReference on key which should be used to encrypt data basing on it.
  2. ParameterTypeRequiredDescription
    dataNSDataYesReference on NSData object which should be encrypted.
    keyNSStringYesReference on key which should be used to encrypt data basing on it.
    errorNSErrorNoReference on pointer into which encryption error will be stored in case of encryption failure. Error can be related to JSON string serialization as well as encryption itself.
NSString *message = @"No one should see me as plain";
NSData *messageData = [message dataUsingEncoding:NSUTF8StringEncoding];
NSString *secretMessage = [PNAES encrypt:messageData withKey:@"my_cipherkey"];
Encrypted Base64-encoded string received from Foundation object. nil will be returned in case of failure.
This function allow to decrypt the data.
To decrypt the data you can use the following method(s) in Objective-C SDK.
  1. ParameterTypeRequiredDescription
    objectNSStringYesReference on previously encrypted Base64-encoded string which should be decrypted.
    keyNSStringYesReference on key which should be used to decrypt data.
  2. ParameterTypeRequiredDescription
    objectNSStringYesReference on previously encrypted Base64-encoded string which should be decrypted.
    keyNSStringYesReference on key which should be used to decrypt data.
    errorNSErrorNoReference on pointer into which decryption error will be stored in case of decryption failure. Error can be related to JSON string deserialization as well as decryption itself.
NSString *encryptedMessage = messagePayload[@"secret"];
NSData *messageData = [PNAES decrypt:encryptedMessage withKey:@"my_cipherkey"];
NSString *decryptedMessage = [[NSString alloc] initWithData:messageData encoding:NSUTF8StringEncoding];
Initial NSData which has been encrypted earlier. nil will be returned in case of decryption error.