iOS SDK V4 Mobile Push API Reference for Realtime Apps
PubNub's Mobile Push Gateway feature enables developers to bridge native PubNub publishing with 3rd-party push notification services including Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).
By using the Mobile Push Gateway, developers can eliminate the need for developing, configuring, and maintaining additional server-side components for third-party push notification providers.
Adding Device to Channel
Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Enable push notifications on provided set of channels.
Method(s)
To run Adding Device to Channel
you can use the following method(s) in the Objective-C SDK:
- (void)addPushNotificationsOnChannels:(NSArray<NSString *> *)channels withDevicePushToken:(NSData *)pushToken andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
Parameter Type Required Description channels
NSArray Yes List of channel
names for which push notifications should beenabled
.pushToken
NSData Yes Device push token which should be used to enabled push notifications on specified set of channels
.block
PNPushNotificationsStateModificationCompletionBlock No Push notifications addition on channels
processing completionblock
which pass only one argument - request processing status to report about how data pushing was successful or not.- (void)addPushNotificationsOnChannels:(NSArray<NSString *> *)channels withDevicePushToken:(id)pushToken pushType:(PNPushType)pushType andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block
Parameter Type Required Description channels
NSArray<NSString *> * Yes List of channel names for which push notifications should be enabled. pushToken
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
block
PNPushNotificationsStateModificationCompletionBlock No Add notifications for channels
request completion block.- (void)addPushNotificationsOnChannels:(NSArray<NSString *> *)channels withDevicePushToken:(id)pushToken pushType:(PNPushType)pushType environment:(PNAPNSEnvironment)environment topic:(NSString *)topic andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block
Parameter Type Required Description channels
NSArray<NSString *> Yes List of channel names for which push notifications should be enabled. pushToken
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
environment
PNAPNSEnvironment Yes One of PNAPNSEnvironment
fields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushType
set toPNAPNS2Push
).topic
NSString Yes Notifications topic name (usually it is application's bundle identifier). block
PNPushNotificationsStateModificationCompletionBlock No Add notifications for channels
request completion block.
Basic Usage
[self.client addPushNotificationsOnChannels:@[@"wwdc",@"google.io"]
withDevicePushToken:self.devicePushToken
andCompletion:^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
// Handle successful push notification enabling on passed channels.
}
else {
/**
Handle modification 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
Response objects which is returned by client when APNS Add Device API is used:
@interface PNErrorData : PNServiceData
// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;
@end
@interface PNAcknowledgmentStatus : PNErrorStatus
// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;
// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;
@end
Other Examples
Example For Method no. 2
[self.client addPushNotificationsOnChannels:@[@"wwdc",@"google.io"] withDevicePushToken:self.devicePushToken pushType:PNAPNSPush andCompletion:^(PNAcknowledgmentStatus *status) { if (!status.isError) { // Push notifications successful enabled on passed channels. } else { /** * Handle modification error. Check 'category' property to find out possible issue because * of which request did fail. * * Request can be resent using: [status retry]; */ } }];
Example For Method no. 3
[self.client addPushNotificationsOnChannels:@[@"wwdc",@"google.io"] withDevicePushToken:self.devicePushToken pushType:PNAPNS2Push environment:PNAPNSProduction topic:@"com.my-application.bundle" andCompletion:^(PNAcknowledgmentStatus *status) { if (!status.isError) { // Push notifications successful enabled on passed channels. } else { /** * Handle modification error. Check 'category' property to find out possible issue because * of which request did fail. * * Request can be resent using: [status retry]; */ } }];
Adding Device to Channel (Builder Pattern)
Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Enable push notifications on provided set of channels.
Method(s)
To run Adding Device to Channel
you can use the following method(s) in the Objective-C SDK
APNS Token:
push().enable().channels(NSArray<NSString *> *).token(id).pushType(PNPushType).environment(PNAPNSEnvironment).topic(NSString *).performWithCompletion(nullable PNPushNotificationsStateModificationCompletionBlock)
Parameter Type Required Description channels
NSArray<NSString *> Yes List of channel names for which push notifications should be enabled. token
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
environment
PNAPNSEnvironment No One of PNAPNSEnvironment
fields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushType
set toPNAPNS2Push
).topic
NSString No Notifications topic name (usually it is application's bundle identifier). block
PNPushNotificationsStateModificationCompletionBlock No Add notifications for channels
request completion block.Note
This method uses the builder pattern, you can remove the arguments which are optional.
-
push().enable().channels(NSArray<NSString *> *).fcmToken(NSString *).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter Type Required Description channels
NSArray<NSString *> * Yes List of channel
names for which push notifications should beenabled
.fcmToken
NSString * Yes FCM-provided device push token which should be used to enabled push notifications on specified set of channels
.completion
PNPushNotificationsStateModificationCompletionBlock No Push notifications addition on channels
processingcompletion block
which pass only one argument - request processing status to report about how data pushing was successful or not.Note
This method uses the builder pattern, you can remove the arguments which are optional.
Basic Usage
self.client.push().enable()
.token(self.devicePushToken)
.channels(@[@"wwdc",@"google.io"])
.pushType(PNAPNSPush)
.performWithCompletion(^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
// Push notifications successful enabled on passed channels.
} else {
/**
* Handle modification error. Check 'category' property to find out possible issue because
* of which request did fail.
*
* Request can be resent using: [status retry];
*/
}
});
self.client.push().enable()
.token(self.devicePushToken)
.channels(@[@"wwdc",@"google.io"])
.pushType(PNAPNS2Push)
.environment(PNAPNSProduction)
.topic(@"com.my-application.bundle")
.performWithCompletion(^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
// Push notifications successful enabled on passed channels.
} else {
/**
* Handle modification error. Check 'category' property to find out possible issue because
* of which request did fail.
*
* Request can be resent using: [status retry];
*/
}
});
self.client.push().enable()
.token(self.devicePushToken)
.channels(@[@"wwdc",@"google.io"])
.pushType(PNFCMPush)
.performWithCompletion(^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
// Push notifications successful enabled on passed channels.
} else {
/**
* Handle modification error. Check 'category' property to find out possible issue because
* of which request did fail.
*
* Request can be resent using: [status retry];
*/
}
});
Response
Response objects which is returned by client when APNS Add Device
API is used:
@interface PNErrorData : PNServiceData
// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;
@end
@interface PNAcknowledgmentStatus : PNErrorStatus
// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;
// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;
@end
Listing Channels For Device
Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Request for all channels on which push notification has been enabled using specified pushToken.
Method(s)
To run Listing Channels For Device
you can use the following method(s) in the Objective-C SDK:
- (void)pushNotificationEnabledChannelsForDeviceWithPushToken:(NSData *)pushToken andCompletion:(PNPushNotificationsStateAuditCompletionBlock)block;
Parameter Type Required Description pushToken
NSData Yes Device push token against which search on PubNub service should be performed. block
PNPushNotificationsStateAuditCompletionBlock Yes Push notifications
status processing completionblock
which pass two arguments: result - in case of successful request processing data field will contain results of pushnotifications
audit operation; status - in case if error occurred during request processing.- (void)pushNotificationEnabledChannelsForDeviceWithPushToken:(id)pushToken pushType:(PNPushType)pushType andCompletion:(PNPushNotificationsStateAuditCompletionBlock)block
Parameter Type Required Description pushToken
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
block
PNPushNotificationsStateAuditCompletionBlock Yes Audit notifications enabled channels
request completion block.- (void)pushNotificationEnabledChannelsForDeviceWithPushToken:(id)pushToken pushType:(PNPushType)pushType environment:(PNAPNSEnvironment)environment topic:(NSString *)topic andCompletion:(PNPushNotificationsStateAuditCompletionBlock)block
Parameter Type Required Description pushToken
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
environment
PNAPNSEnvironment Yes One of PNAPNSEnvironment
fields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushType
set toPNAPNS2Push
).topic
NSString Yes Notifications topic name (usually it is application's bundle identifier). block
PNPushNotificationsStateAuditCompletionBlock Yes Audit notifications enabled channels
request completion block.
Basic Usage
[self.client pushNotificationEnabledChannelsForDeviceWithPushToken:self.devicePushToken
andCompletion:^(PNAPNSEnabledChannelsResult *result,
PNErrorStatus *status) {
if (!status) {
// Handle downloaded list of channels using: result.data.channels
}
else {
/**
Handle audition 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
Response objects which is returned by clientAPNS List Devices
API is used:
@interface PNAPNSEnabledChannelsData : PNServiceData
// Channels with active push notifications.
@property (nonatomic, readonly, strong) NSArray<NSString *> *channels;
@end
@interface PNAPNSEnabledChannelsResult : PNResult
// APNS enabled channels audit request processed information.
@property (nonatomic, readonly, strong) PNAPNSEnabledChannelsData *data;
@end
Error response which is used in case of APNS List Devices
API call failure:
@interface PNErrorData : PNServiceData
// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;
@end
@interface PNErrorStatus : PNStatus
// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;
// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;
@end
Other Examples
Example For Method no. 2
[self.client pushNotificationEnabledChannelsForDeviceWithPushToken:self.devicePushToken pushType:PNAPNSPush andCompletion:^(PNAPNSEnabledChannelsResult *result, PNErrorStatus *status) { if (!status.isError) { // Handle downloaded list of channels using: result.data.channels } else { /** * Handle audition error. Check 'category' property to find out possible issue because of * which request did fail. * * Request can be resent using: [status retry]; */ } }];
Example For Method no. 3
[self.client pushNotificationEnabledChannelsForDeviceWithPushToken:self.devicePushToken pushType:PNAPNS2Push environment:PNAPNSDevelopment topic:@"com.my-application.bundle" andCompletion:^(PNAPNSEnabledChannelsResult *result, PNErrorStatus *status) { if (!status.isError) { // Handle downloaded list of channels using: result.data.channels } else { /** * Handle audition error. Check 'category' property to find out possible issue because of * which request did fail. * * Request can be resent using: [status retry]; */ } }];
Listing Channels For Device (Builder Pattern)
Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Request for all channels on which push notification has been enabled using specified pushToken.
Method(s)
To run Listing Channels For Device
you can use the following method(s) in the Objective-C SDK
APNS Token:
push().audit().token(id).pushType(PNPushType).environment(PNAPNSEnvironment).topic(NSString *).performWithCompletion(PNPushNotificationsStateAuditCompletionBlock)
Parameter Type Required Description token
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
environment
PNAPNSEnvironment No One of PNAPNSEnvironment
fields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushType
set toPNAPNS2Push
).topic
NSString No Notifications topic name (usually it is application's bundle identifier). block
PNPushNotificationsStateAuditCompletionBlock Yes Audit notifications enabled channels
request completion block.Note
This method uses the builder pattern, you can remove the arguments which are optional.
-
push().audit().fcmToken(NSString *).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter Type Required Description fcmToken
NSString * Yes FCM-provided device push token
against which search on PubNub service should be performed.completion
PNPushNotificationsStateAuditCompletionBlock Yes Push notifications
status processing completionblock
which pass two arguments:result
- in case of successful request processingdata
field will contain results of pushnotifications
audit operation;status
- in case if error occurred during request processing.Note
This method uses the builder pattern, you can remove the arguments which are optional.
Basic Usage
self.client.push().audit()
.token(self.devicePushToken)
.pushType(PNAPNS2Push)
.environment(PNAPNSProduction)
.topic(@"com.my-application.bundle")
.performWithCompletion(^(PNAPNSEnabledChannelsResult *result, PNErrorStatus *status) {
if (!status.isError) {
// Handle downloaded list of channels using: result.data.channels
} else {
/**
* Handle audition error. Check 'category' property to find out possible issue because of
* which request did fail.
*
* Request can be resent using: [status retry];
*/
}
});
self.client.push().audit()
.fcmToken(self.pushToken)
.performWithCompletion(^(PNAPNSEnabledChannelsResult *result, PNErrorStatus *status) {
if (!status) {
// Handle downloaded list of channels using: result.data.channels
} else {
/**
Handle audition 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
Response objects which is returned by client when APNS List Devices
API is used:
@interface PNAPNSEnabledChannelsData : PNServiceData
// Channels with active push notifications.
@property (nonatomic, readonly, strong) NSArray<NSString *> *channels;
@end
@interface PNAPNSEnabledChannelsResult : PNResult
// APNS enabled channels audit request processed information.
@property (nonatomic, readonly, strong) PNAPNSEnabledChannelsData *data;
@end
Error response which is used in case of APNS List Devices
API call failure:
@interface PNErrorData : PNServiceData
// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;
@end
@interface PNErrorStatus : PNStatus
// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;
// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;
@end
Removing Device From Channel
Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Disable push notifications on provided set of channels.
Method(s)
To run Removing Device From Channel
you can use the following method(s) in the Objective-C SDK:
- (void)removePushNotificationsFromChannels:(NSArray<NSString *> *)channels withDevicePushToken:(NSData *)pushToken andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
Parameter Type Required Description channels
NSArray Yes List of channel names for which push notifications should be disabled. If passed list is empty all notifications will be disabled.
pushToken
NSData Yes Device push token which should be used to disable push notifications
on specified set ofchannels
.block
PNPushNotificationsStateModificationCompletionBlock No Push notifications
removal fromchannels
processing completionblock
which pass only one argument - request processingstatus
to report about how data pushing was successful or not.- (void)removePushNotificationsFromChannels:(NSArray<NSString *> *)channels withDevicePushToken:(id)pushToken pushType:(PNPushType)pushType andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block
Parameter Type Required Description channels
NSArray<NSString *> * Yes List of channel names for which push notifications should be disabled. pushToken
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
block
PNPushNotificationsStateModificationCompletionBlock No Remove notifications from channels
request completion block.- (void)removePushNotificationsFromChannels:(NSArray<NSString *> *)channels withDevicePushToken:(id)pushToken pushType:(PNPushType)pushType environment:(PNAPNSEnvironment)environment topic:(NSString *)topic andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block
Parameter Type Required Description channels
NSArray<NSString *> * Yes List of channel names for which push notifications should be disabled. pushToken
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
environment
PNAPNSEnvironment Yes One of PNAPNSEnvironment
fields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushType
set toPNAPNS2Push
).topic
NSString Yes Notifications topic name (usually it is application's bundle identifier). block
PNPushNotificationsStateModificationCompletionBlock No Remove notifications from channels
request completion block.
Basic Usage
[self.client removePushNotificationsFromChannels:@[@"wwdc",@"google.io"]
withDevicePushToken:self.devicePushToken
andCompletion:^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
// Handle successful push notification disabling on passed channels.
}
else {
/**
Handle modification 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
Response objects which is returned by client when APNS Remove Device API is used:
@interface PNErrorData : PNServiceData
// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;
@end
@interface PNAcknowledgmentStatus : PNErrorStatus
// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;
// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;
@end
Other Examples
Example For Method no. 2
[self.client removePushNotificationsFromChannels:@[@"wwdc",@"google.io"] withDevicePushToken:self.devicePushToken pushType:PNAPNSPush andCompletion:^(PNAcknowledgmentStatus *status) { if (!status.isError) { // Push notification successfully disabled on passed channels. } else { /** * Handle modification error. Check 'category' property to find out possible issue because * of which request did fail. * * Request can be resent using: [status retry]; */ } }];
Example For Method no. 3
[self.client removePushNotificationsFromChannels:@[@"wwdc",@"google.io"] withDevicePushToken:self.devicePushToken pushType:PNAPNS2Push environment:PNAPNSProduction topic:@"com.my-application.bundle" andCompletion:^(PNAcknowledgmentStatus *status) { if (!status.isError) { // Push notification successfully disabled on passed channels. } else { /** * Handle modification error. Check 'category' property to find out possible issue because * of which request did fail. * * Request can be resent using: [status retry]; */ } }];
Removing Device From Channel (Builder Pattern)
Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Disable push notifications on provided set of channels.
Method(s)
To run Removing Device From Channel
you can use the following method(s) in the Objective-C SDK
APNS Token:
push().disable().channels(NSArray<NSString *> *).token(id).pushType(PNPushType).environment(PNAPNSEnvironment).topic(NSString *).performWithCompletion(nullable PNPushNotificationsStateModificationCompletionBlock)
Parameter Type Required Description channels
NSArray<NSString *> * Yes List of channel names for which push notifications should be disabled. token
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
environment
PNAPNSEnvironment No One of PNAPNSEnvironment
fields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushType
set toPNAPNS2Push
).topic
NSString No Notifications topic name (usually it is application's bundle identifier). block
PNPushNotificationsStateModificationCompletionBlock No Remove notifications from channels
request completion block.Note
This method uses the builder pattern, you can remove the arguments which are optional.
-
push().disable().channels(NSArray<NSString *> *).fcmToken(NSString *).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter Type Required Description channels
NSArray<NSString *> * Yes List of channel names for which push notifications should be disabled. If passed list is empty all notifications will be disabled
.fcmToken
NSString * Yes FCM-provided device push token which should be used to disable push notifications
on specified set ofchannels
.completion
PNPushNotificationsStateAuditCompletionBlock No Push notifications
removal fromchannels
processing completionblock
which pass only one argument - request processingstatus
to report about how data pushing was successful or not.Note
This method uses the builder pattern, you can remove the arguments which are optional.
Basic Usage
self.client.push().disable()
.token(self.devicePushToken)
.channels(@[@"wwdc",@"google.io"])
.pushType(PNAPNS2Push)
.environment(PNAPNSProduction)
.topic(@"com.my-application.bundle")
.performWithCompletion(^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
// Push notification successfully disabled on passed channels.
} else {
/**
* Handle modification error. Check 'category' property to find out possible issue because
* of which request did fail.
*
* Request can be resent using: [status retry];
*/
}
});
self.client.push().disable()
.channels(@[@"channel1", @"channel2"])
.fcmToken(self.pushToken)
.performWithCompletion(^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
// Handle successful push notification enabling on passed channels.
} else {
/**
Handle modification 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
Response objects which is returned by client when APNS Remove Device API is used:
@interface PNErrorData : PNServiceData
// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;
@end
@interface PNAcknowledgmentStatus : PNErrorStatus
// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;
// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;
@end
Remove all push notifications
Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Disable push notifications from all channels registered with the specified pushToken.
Method(s)
To run Remove all push notifications
you can use the following method(s) in the Objective-C SDK:
- (void)removeAllPushNotificationsFromDeviceWithPushToken:(NSData *)pushToken andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
Parameter Type Required Description pushToken
NSData Yes Device push token which should be used to disable push notifications
on specified set ofchannels
.block
PNPushNotificationsStateModificationCompletionBlock No Push notifications
removal from device processing completionblock
which pass only one argument - request processingstatus
to report about how data pushing was successful or not.- (void)removeAllPushNotificationsFromDeviceWithPushToken:(id)pushToken pushType:(PNPushType)pushType andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block
Parameter Type Required Description pushToken
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
block
PNPushNotificationsStateModificationCompletionBlock No Remove all notifications
request completion block.- (void)removeAllPushNotificationsFromDeviceWithPushToken:(id)pushToken pushType:(PNPushType)pushType environment:(PNAPNSEnvironment)environment topic:(NSString *)topic andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block
Parameter Type Required Description channels
NSArray<NSString *> * Yes List of channel names for which push notifications should be disabled. pushToken
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
environment
PNAPNSEnvironment Yes One of PNAPNSEnvironment
fields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushType
set toPNAPNS2Push
).topic
NSString Yes Notifications topic name (usually it is application's bundle identifier). block
PNPushNotificationsStateModificationCompletionBlock No Remove all notifications
request completion block.
Basic Usage
Remove all push notifications:
[self.client removeAllPushNotificationsFromDeviceWithPushToken:self.devicePushToken
andCompletion:^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
/**
Handle successful push notification disabling for all channels associated with
specified device push token.
*/
}
else {
/**
Handle modification 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
Response objects which is returned by client when APNS Remove All Devices API is used:
@interface PNErrorData : PNServiceData
// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;
@end
@interface PNAcknowledgmentStatus : PNErrorStatus
// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;
// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;
@end
Other Examples
Example For Method no. 2
[self.client removeAllPushNotificationsFromDeviceWithPushToken:self.devicePushToken pushType:PNAPNSPush andCompletion:^(PNAcknowledgmentStatus *status) { if (!status.isError) { /** * Push notification successfully disabled for all channels associated with specified * device push token. */ } else { /** * Handle modification error. Check 'category' property to find out possible issue because * of which request did fail. * * Request can be resent using: [status retry]; */ } }];
Example For Method no. 3
[self.client removeAllPushNotificationsFromDeviceWithPushToken:self.devicePushToken pushType:PNAPNS2Push environment:PNAPNSProduction topic:@"com.my-application.bundle" andCompletion:^(PNAcknowledgmentStatus *status) { if (!status.isError) { /** * Push notification successfully disabled for all channels associated with specified * device push token. */ } else { /** * Handle modification error. Check 'category' property to find out possible issue because * of which request did fail. * * Request can be resent using: [status retry]; */ } }];
Remove all push notifications (Builder Pattern)
Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Method(s)
push().disableAll().token(id).pushType(PNPushType).environment(PNAPNSEnvironment).topic(NSString *).performWithCompletion(nullable PNPushNotificationsStateModificationCompletionBlock)
Parameter Type Required Description token
id Yes Device token / identifier which depending from passed pushType
should beNSData
(forPNAPNS2Push
andPNAPNSPush
) orNSString
for other.pushType
PNPushType Yes One of PNPushType
fields which specify service to manage notifications for device specified withpushToken
.
Available push types:PNAPNSPush
- Apple Push Notification ServicePNAPNS2Push
- Apple Push Notification Service over HTTP/2PNFCMPush
- Firebase Cloud Messaging (Google Cloud Messaging)PNMPNSPush
- Microsoft Push Notification Service
environment
PNAPNSEnvironment No One of PNAPNSEnvironment
fields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushType
set toPNAPNS2Push
).topic
NSString No Notifications topic name (usually it is application's bundle identifier). block
PNPushNotificationsStateModificationCompletionBlock No Remove all notifications
request completion block.Note
This method uses the builder pattern, you can remove the arguments which are optional.
Basic Usage
Remove all push notifications, using Builder Pattern:
self.client.push().disableAll()
.token(self.devicePushToken)
.pushType(PNAPNS2Push)
.environment(PNAPNSProduction)
.topic(@"com.my-application.bundle")
.performWithCompletion(^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
/**
* Push notification successfully disabled for all channels associated with specified
* device push token.
*/
} else {
/**
* Handle modification error. Check 'category' property to find out possible issue because
* of which request did fail.
*
* Request can be resent using: [status retry];
*/
}
});
Response
Response object returned by the client when APNS Remove All Devices
API is used:
@interface PNErrorData : PNServiceData
// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;
@end
@interface PNAcknowledgmentStatus : PNErrorStatus
// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;
// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;
@end