Utility Methods API for Objective-C SDK
The methods on this page are utility methods that don't fit into other categories.
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 Objective-C SDK:
1- (void)sizeOfMessage:(id)message
2 toChannel:(NSString *)channel
3 withCompletion:(PNMessageSizeCalculationCompletionBlock)block;
| Parameter | Description |
|---|---|
message *Type: id | Message for which size should be calculated. |
channel *Type: NSString | Name of the channel to which message should be sent (it is part of request URI). |
block *Type: PNMessageSizeCalculationCompletionBlock | Referecnce on block which should be sent, when message size calculation will be completed. |
1- (void)sizeOfMessage:(id)message
2 toChannel:(NSString *)channel
3 compressed:(BOOL)compressMessage
4 withCompletion:(PNMessageSizeCalculationCompletionBlock)block;
| Parameter | Description |
|---|---|
message *Type: id | Message for which size should be calculated. |
channel *Type: NSString | Name of the channel to which message should be sent (it is part of request URI). |
compressMessage *Type: Bool | YES in case if message should be compressed before sending to PubNub network. |
block *Type: PNMessageSizeCalculationCompletionBlock | Referecnce on block which should be sent, when message size calculation will be completed. |
1- (void)sizeOfMessage:(id)message
2 toChannel:(NSString *)channel
3 storeInHistory:(BOOL)shouldStore
4 withCompletion:(PNMessageSizeCalculationCompletionBlock)block;
| Parameter | Description |
|---|---|
message *Type: id | Message for which size should be calculated. |
channel *Type: NSString | Name of the channel to which message should be sent (it is part of request URI). |
shouldStore *Type: Bool | YES in case if message should be stored in Message Persistence. |
block *Type: PNMessageSizeCalculationCompletionBlock | Referecnce on block which should be sent, when message size calculation will be completed. |
1- (void)sizeOfMessage:(id)message
2 toChannel:(NSString *)channel
3 compressed:(BOOL)compressMessage
4 storeInHistory:(BOOL)shouldStore
5 withCompletion:(PNMessageSizeCalculationCompletionBlock)block;
| Parameter | Description |
|---|---|
message *Type: id | Message for which size should be calculated. |
channel *Type: NSString | Name of the channel to which message should be sent (it is part of request URI). |
compressMessage *Type: Bool | YES in case if message should be compressed before sending to PubNub network. |
shouldStore *Type: Bool | NO in case if message shouldn't be available after it has been sent via Message Persistence API methods group. |
block *Type: PNMessageSizeCalculationCompletionBlock | Referecnce on block which should be sent, when message size calculation will be completed. |
1- (void)sizeOfMessage:(id)message
2 toChannel:(NSString *)channel
3 withMetadata:(nullable NSDictionary<NSString *, id> *)metadata
4 completion:(PNMessageSizeCalculationCompletionBlock)block;
| Parameter | Description |
|---|---|
message *Type: id | The message for which the size needs be calculated. |
channel *Type: NSString | The channel on which the message has to be sent (it is part of request URI). |
metadataType: NSDictionary | NSDictionary with values which should be used by PubNub service to filter messages. |
block *Type: PNMessageSizeCalculationCompletionBlock | Completion block which will be called when the message size calculation is complete. |
1- (void)sizeOfMessage:(id)message
2 toChannel:(NSString *)channel
3 compressed:(BOOL)compressMessage
4 withMetadata:(nullable NSDictionary<NSString *, id> *)metadata
5 completion:(PNMessageSizeCalculationCompletionBlock)block;
| Parameter | Description |
|---|---|
message *Type: id | The message for which the size needs be calculated. |
channel *Type: NSString | The channel on which the message has to be sent (it is part of request URI). |
compressMessage *Type: Bool | Should be true if the message is compressed before sending to PubNub network. |
metadataType: NSDictionary | NSDictionary with values which should be used by PubNub service to filter messages. |
block *Type: PNMessageSizeCalculationCompletionBlock | Completion block which will be called when the message size calculation is complete. |
1- (void)sizeOfMessage:(id)message
2 toChannel:(NSString *)channel
3 storeInHistory:(BOOL)shouldStore
4 withMetadata:(nullable NSDictionary<NSString *, id> *)metadata
5 completion:(PNMessageSizeCalculationCompletionBlock)block;
| Parameter | Description |
|---|---|
message *Type: id | The message for which the size needs be calculated. |
channel *Type: NSString | The channel on which the message has to be sent (it is part of request URI). |
shouldStore *Type: Bool | Should be true if the message is marked to be stored in history. |
metadataType: NSDictionary | NSDictionary with values which should be used by PubNub service to filter messages. |
block *Type: PNMessageSizeCalculationCompletionBlock | Completion block which will be called when the message size calculation is complete. |
1- (void)sizeOfMessage:(id)message
2 toChannel:(NSString *)channel
3 compressed:(BOOL)compressMessage
4 storeInHistory:(BOOL)shouldStore
5 withMetadata:(nullable NSDictionary<NSString *, id> *)metadata
6 completion:(PNMessageSizeCalculationCompletionBlock)block;
| Parameter | Description |
|---|---|
message *Type: id | The message for which the size needs be calculated. |
channel *Type: NSString | The channel on which the message has to be sent (it is part of request URI). |
shouldStore *Type: Bool | Should be true if the message is marked to be stored in history. |
compressMessage *Type: Bool | Should be true if the message is compressed before sending to PubNub network. |
metadataType: NSDictionary | NSDictionary with values which should be used by PubNub service to filter messages. |
block *Type: PNMessageSizeCalculationCompletionBlock | Completion block which will be called when the message size calculation is complete. |
Sample code
Get message size
1[self.client sizeOfMessage: @{@"Hello": @"world"} toChannel: @"announcement"
2 withCompletion:^(NSInteger size) {
3
4 // Process calculated target message size.
5 }];
Returns
The message size
Other examples
Get size of message with metadata
1[self.client sizeOfMessage: @{@"Hello": @"World"} toChannel: @"announcement"
2 withMetadata: @{@"senderID": @"bob"} completion:^(NSInteger size) {
3
4 // Process calculated target message size.
5}];
Push notification configuration
PNAPNSNotificationConfiguration
PNAPNSNotificationConfiguration instance allow to configure how notification should be delivered using HTTP/2-based APNs.
Method(s)
1+ (instancetype)defaultConfiguration
Create default configuration with single target configured against PNAPNSDevelopment environment NSBundle.mainBundle.bundleIdentifier as topic name.
1+ (instancetype)configurationWithTargets:(NSArray<PNAPNSNotificationTarget *> *)targets
| Parameter | Description |
|---|---|
targets *Type: NSArray< [PNAPNSNotificationTarget](#pnapnsnotificationtarget)*> * | List of topics which should receive this notification. Default target with NSBundle.mainBundle.bundleIdentifier topic and PNAPNSDevelopment environment will be used if list is empty. |
1+ (instancetype)configurationWithCollapseID:(nullable NSString *)collapseId
2 expirationDate:(nullable NSDate *)date
3 targets:(NSArray<PNAPNSNotificationTarget *> *)targets;
| Parameter | Description |
|---|---|
collapseIdType: NSString | Notification group / collapse identifier. Value will be used in APNs POST request as apns-collapse-id header value. |
dateType: NSDate | Date till which APNS will try to deliver notification to target device. Value will be used in APNs POST request as apns-expiration header value. |
targets *Type: NSArray< [PNAPNSNotificationTarget](#pnapnsnotificationtarget)*> * | List of topics which should receive this notification. Default target with NSBundle.mainBundle.bundleIdentifier topic and PNAPNSDevelopment environment will be used if list is empty. |
Sample code
Create and configure configuration instance which will collapse invitation notifications and retry to deliver notification (APNS) for next 10 seconds if device off-line:
1PNAPNSNotificationConfiguration *configuration = nil;
2PNNotificationsPayload *builder = nil;
3
4PNAPNSNotificationTarget *target = [PNAPNSNotificationTarget targetForTopic:@"com.meetings.chat.app"];
5NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:10];
6configuration = [PNAPNSNotificationConfiguration configurationWithCollapseID:@"invitations"
7 expirationDate:expirationDate
8 targets:@[target]];
Response
Configured and ready to use PNAPNSNotificationConfiguration instance.
PNAPNSNotificationPayload
PNAPNSNotificationPayload instance provides access to options specific only to mobile push notifications sent with APNs.
Properties
| Parameter | Description |
|---|---|
configurationsType: NSArray< [PNAPNSNotificationConfiguration](#pnapnsnotificationconfiguration)*> * | List of HTTP/2-based APNs delivery configurations. If list is empty when payload for PNAPNS2Push has been requested, it will create default configuration for PNAPNSDevelopment environment and NSBundle.mainBundle.bundleIdentifier as topic name. |
notificationType: NSMutableDictionary | Object with parameters which specify user-visible key-value pairs. |
payloadType: NSMutableDictionary | Platform specific notification payload. In addition to data required to make notification visual presentation it can be used to pass additional information which should be sent to remote device. |
silentType: BOOL | Whether operation system should handle notification layout by default or not. alert, sound and badge will be removed from resulting payload if set to YES. |
PNAPNSNotificationTarget
PNAPNSNotificationTarget instance allow to configure APNS notification recipient.