On this page

Mobile Push Notifications API for Objective-C SDK

The Mobile Push Notifications feature connects native PubNub publishing to third-party push services. Supported services include Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

To learn more, read about Mobile Push Notifications.

APNs version support

PubNub Objective-C SDK supports both the HTTP/2-based Apple Push Notification service (APNs) and the already deprecated legacy binary protocol for APNs Mobile Push Notifications. Depending on the APNs version you use in your SDK, set pushType in methods to either PNAPNS2Push or PNAPNSPush.

Add a device to a push notifications channel

note
Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

Enable mobile push notifications on a set of channels.

Method(s)

To run Adding Device to Channel, you can use the following method(s) in the Objective-C SDK:

1- (void)addPushNotificationsOnChannels:(NSArray<NSString *> *)channels 
2 withDevicePushToken:(NSData *)pushToken
3 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
* required
ParameterDescription
channels *
Type: NSArray
Channels to enable for push notifications.
pushToken *
Type: NSData
Device push token.
block
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block with request status.
1- (void)addPushNotificationsOnChannels:(NSArray<NSString *> *)channels 
2 withDevicePushToken:(id)pushToken
3 pushType:(PNPushType)pushType
4 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
* required
ParameterDescription
channels *
Type: NSArray<NSString *> *
Channels to enable for push notifications.
pushToken *
Type: id
Device token (NSString).
pushType *
Type: PNPushType
Accepted values:
  • PNFCMPush - Firebase Cloud Messaging (Google Cloud Messaging)
block
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block.
1- (void)addPushNotificationsOnChannels:(NSArray<NSString *> *)channels 
2 withDevicePushToken:(id)pushToken
3 pushType:(PNPushType)pushType
4 environment:(PNAPNSEnvironment)environment
5 topic:(NSString *)topic
6 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
* required
ParameterDescription
channels *
Type: NSArray<NSString *> *
Channels to enable for push notifications.
pushToken *
Type: id
Device token (NSData).
pushType *
Type: PNPushType
Accepted values:
  • PNAPNS2Push - Apple Push Notification service over HTTP/2
environment *
Type: PNAPNSEnvironment
APNs environment (APNS2 only).
topic *
Type: NSString
APNs topic (bundle identifier).
block
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block.

Sample code

Add device to channel

1#import <Foundation/Foundation.h>
2#import <PubNub/PubNub.h>
3
4// Basic configuration
5PNConfiguration *config = [PNConfiguration configurationWithPublishKey:@"demo"
6 subscribeKey:@"demo"
7 userID:@"pushUser"];
8
9// Create a PubNub client instance
10PubNub *client = [PubNub clientWithConfiguration:config];
11
12// Simulating a device token for example purposes
13// In a real app, you would get this from the system
14NSData *devicePushToken = [@"sample-device-token-12345" dataUsingEncoding:NSUTF8StringEncoding];
15
show all 76 lines

Response

Response objects returned by the client when the APNS Add Device API is used:

1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
show all 16 lines

Other examples

  1. Example for method no. 2

    1[self.client addPushNotificationsOnChannels:@[@"wwdc",@"google.io"]
    2 withDevicePushToken:self.devicePushToken
    3 pushType:PNFCMPush
    4 andCompletion:^(PNAcknowledgmentStatus *status) {
    5
    6 if (!status.isError) {
    7 // Push notifications successful enabled on passed channels.
    8 } else {
    9 /**
    10 * Handle modification error. Check 'category' property to find out possible issue because
    11 * of which request did fail.
    12 *
    13 * Request can be resent using: [status retry];
    14 */
    15 }
    show all 16 lines
  2. Example for method no. 3

    1[self.client addPushNotificationsOnChannels:@[@"wwdc",@"google.io"]
    2 withDevicePushToken:self.devicePushToken
    3 pushType:PNAPNS2Push
    4 environment:PNAPNSProduction
    5 topic:@"com.my-application.bundle"
    6 andCompletion:^(PNAcknowledgmentStatus *status) {
    7
    8 if (!status.isError) {
    9 // Push notifications successful enabled on passed channels.
    10 } else {
    11 /**
    12 * Handle modification error. Check 'category' property to find out possible issue because
    13 * of which request did fail.
    14 *
    15 * Request can be resent using: [status retry];
    show all 18 lines

Add a device to a push notifications channel (builder pattern)

note
Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

Enable mobile push notifications on a set of channels.

Method(s)

Use the following builder methods:

APNS2 token

1push()
2 .enable()
3 .token(id)
4 .channels(NSArray<NSString *> *)
5 .pushType(PNPushType)
6 .environment(PNAPNSEnvironment)
7 .topic(NSString *)
8 .performWithCompletion(nullable PNPushNotificationsStateModificationCompletionBlock);
* required
ParameterDescription
channels *
Type: NSArray<NSString *>
Channels to enable for push notifications.
token *
Type: id
Device token (NSData).
pushType *
Type: PNPushType
Accepted values:
  • PNAPNS2Push - Apple Push Notification service over HTTP/2
environment
Type: PNAPNSEnvironment
APNs environment (APNS2 only).
topic
Type: NSString
APNs topic (bundle identifier).
block
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block.
Note

This method uses the builder pattern. You can omit optional arguments.

FCM token

1push()
2 .enable()
3 .fcmToken(NSString *)
4 .channels(NSArray<NSString *> *)
5 .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock);
6
* required
ParameterDescription
channels *
Type: NSArray<NSString *> *
Channels to enable for push notifications.
fcmToken *
Type: NSString *
FCM device push token.
completion
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block with request status.
Note

This method uses the builder pattern, you can remove the arguments which are optional.

Sample code

APNS2 token

1self.client.push().enable()
2 .token(self.devicePushToken)
3 .channels(@[@"wwdc",@"google.io"])
4 .pushType(PNAPNS2Push)
5 .environment(PNAPNSProduction)
6 .topic(@"com.my-application.bundle")
7 .performWithCompletion(^(PNAcknowledgmentStatus *status) {
8 if (!status.isError) {
9 // Push notifications successful enabled on passed channels.
10 } else {
11 /**
12 * Handle modification error. Check 'category' property to find out possible issue because
13 * of which request did fail.
14 *
15 * Request can be resent using: [status retry];
show all 18 lines

FCM token

1self.client.push().enable()
2 .token(self.devicePushToken)
3 .channels(@[@"wwdc",@"google.io"])
4 .pushType(PNFCMPush)
5 .performWithCompletion(^(PNAcknowledgmentStatus *status) {
6 if (!status.isError) {
7 // Push notifications successful enabled on passed channels.
8 } else {
9 /**
10 * Handle modification error. Check 'category' property to find out possible issue because
11 * of which request did fail.
12 *
13 * Request can be resent using: [status retry];
14 */
15 }
show all 16 lines

Response

Response objects returned by the client when the APNS Add Device API is used:

1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
show all 16 lines

List push notifications channels for a device (builder pattern)

note
Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

List channels that have push notifications enabled for the specified device token.

Method(s)

To run Listing Channels For Device, you can use the following method(s) in the Objective-C SDK:

1- (void)pushNotificationEnabledChannelsForDeviceWithPushToken:(NSData *)pushToken 
2 andCompletion:(PNPushNotificationsStateAuditCompletionBlock)block;
* required
ParameterDescription
pushToken *
Type: NSData
Device push token against which search on PubNub service should be performed.
block *
Type: PNPushNotificationsStateAuditCompletionBlock
Push notifications status processing completion block which pass two arguments: result - in case of successful request processing data field will contain results of push notifications audit operation; status - in case if an error occurred during request processing.
1- (void)pushNotificationEnabledChannelsForDeviceWithPushToken:(id)pushToken 
2 pushType:(PNPushType)pushType
3 andCompletion:(PNPushNotificationsStateAuditCompletionBlock)block;
* required
ParameterDescription
pushToken *
Type: id
Device token / identifier that you must set to NSString
pushType *
Type: PNPushType
One of PNPushType fields which specify service to manage notifications for device specified with pushToken.
Available push types:
  • PNFCMPush - Firebase Cloud Messaging (Google Cloud Messaging)
block *
Type: PNPushNotificationsStateAuditCompletionBlock
Audit notifications enabled channels request completion block.
1- (void)pushNotificationEnabledChannelsForDeviceWithPushToken:(id)pushToken 
2 pushType:(PNPushType)pushType
3 environment:(PNAPNSEnvironment)environment
4 topic:(NSString *)topic
5 andCompletion:(PNPushNotificationsStateAuditCompletionBlock)block;
* required
ParameterDescription
pushToken *
Type: id
Device token / identifier that you must set to either NSData (for PNAPNS2Push and PNAPNSPush) or NSString for other, depending on the pushType passed.
pushType *
Type: PNPushType
One of PNPushType fields which specify service to manage notifications for device specified with pushToken.
Available push types:
  • PNAPNS2Push - Apple Push Notification service over HTTP/2
environment *
Type: PNAPNSEnvironment
One of PNAPNSEnvironment fields which specify environment within which device should manage list of channels with enabled notifications (works only if pushType set to PNAPNS2Push).
topic *
Type: NSString
Notifications topic name (usually it is application's bundle identifier).
block *
Type: PNPushNotificationsStateAuditCompletionBlock
Audit notifications enabled channels request completion block.

Sample code

List channels for device

1[self.client pushNotificationEnabledChannelsForDeviceWithPushToken:self.devicePushToken
2 andCompletion:^(PNAPNSEnabledChannelsResult *result,
3 PNErrorStatus *status) {
4 if (!status) {
5
6 // Handle downloaded list of channels using: result.data.channels
7 }
8 else {
9
10 /**
11 Handle audition error. Check 'category' property
12 to find out possible reason because of which request did fail.
13 Review 'errorData' property (which has PNErrorData data type) of status
14 object to get additional information about issue.
15
show all 19 lines

Response

Response objects returned by the client when the APNS List Devices API is used:

1@interface PNAPNSEnabledChannelsData : PNServiceData
2
3// Channels with active mobile push notifications.
4@property (nonatomic, readonly, strong) NSArray<NSString *> *channels;
5
6@end
7
8@interface PNAPNSEnabledChannelsResult : PNResult
9
10// APNS enabled channels audit request processed information.
11@property (nonatomic, readonly, strong) PNAPNSEnabledChannelsData *data;
12
13@end

Error response which is used in case of APNS List Devices API call failure:

1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
show all 16 lines

Other examples

  1. Example for method no. 2

    1[self.client pushNotificationEnabledChannelsForDeviceWithPushToken:self.devicePushToken
    2 pushType:PNFCMPush
    3 andCompletion:^(PNFCMEnabledChannelsResult *result, PNErrorStatus *status) {
    4
    5 if (!status.isError) {
    6 // Handle downloaded list of channels using: result.data.channels
    7 } else {
    8 /**
    9 * Handle audition error. Check 'category' property to find out possible issue because of
    10 * which request did fail.
    11 *
    12 * Request can be resent using: [status retry];
    13 */
    14 }
    15}];
  2. Example for method no. 3

    1[self.client pushNotificationEnabledChannelsForDeviceWithPushToken:self.devicePushToken
    2 pushType:PNAPNS2Push
    3 environment:PNAPNSDevelopment
    4 topic:@"com.my-application.bundle"
    5 andCompletion:^(PNAPNSEnabledChannelsResult *result, PNErrorStatus *status) {
    6
    7 if (!status.isError) {
    8 // Handle downloaded list of channels using: result.data.channels
    9 } else {
    10 /**
    11 * Handle audition error. Check 'category' property to find out possible issue because of
    12 * which request did fail.
    13 *
    14 * Request can be resent using: [status retry];
    15 */
    show all 17 lines

List channels for device (builder pattern)

Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

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

APNS2 token

1push()
2 .audit()
3 .token(id)
4 .pushType(PNPushType)
5 .environment(PNAPNSEnvironment)
6 .topic(NSString *)
7 .performWithCompletion(PNPushNotificationsStateAuditCompletionBlock);
8
* required
ParameterDescription
token *
Type: id
Device token (NSData).
pushType *
Type: PNPushType
Accepted values:
  • PNAPNS2Push - Apple Push Notification service over HTTP/2
environment
Type: PNAPNSEnvironment
APNs environment (APNS2 only).
topic
Type: NSString
APNs topic (bundle identifier).
block *
Type: PNPushNotificationsStateAuditCompletionBlock
Completion block.
Note

This method uses the builder pattern. You can omit optional arguments.

FCM token

1push()
2 .audit()
3 .fcmToken(NSString *)
4 .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock);
* required
ParameterDescription
fcmToken *
Type: NSString *
FCM device push token.
completion *
Type: PNPushNotificationsStateAuditCompletionBlock
Completion block with result and status.
Note

This method uses the builder pattern. You can omit optional arguments.

Sample code

APNS2 token

1self.client.push().audit()
2 .token(self.devicePushToken)
3 .pushType(PNAPNS2Push)
4 .environment(PNAPNSProduction)
5 .topic(@"com.my-application.bundle")
6 .performWithCompletion(^(PNAPNSEnabledChannelsResult *result, PNErrorStatus *status) {
7 if (!status.isError) {
8 // Handle downloaded list of channels using: result.data.channels
9 } else {
10 /**
11 * Handle audition error. Check 'category' property to find out possible issue because of
12 * which request did fail.
13 *
14 * Request can be resent using: [status retry];
15 */
show all 17 lines

FCM token

1self.client.push().audit()
2 .fcmToken(self.pushToken)
3 .performWithCompletion(^(PNAPNSEnabledChannelsResult *result, PNErrorStatus *status) {
4 if (!status) {
5 // Handle downloaded list of channels using: result.data.channels
6 } else {
7 /**
8 Handle audition error. Check 'category' property
9 to find out possible reason because of which request did fail.
10 Review 'errorData' property (which has PNErrorData data type) of status
11 object to get additional information about issue.
12
13 Request can be resent using: [status retry];
14 */
15 }
show all 16 lines

Response

Response objects returned by the client when the APNS List Devices API is used:

1@interface PNAPNSEnabledChannelsData : PNServiceData
2
3// Channels with active mobile push notifications.
4@property (nonatomic, readonly, strong) NSArray<NSString *> *channels;
5
6@end
7
8@interface PNAPNSEnabledChannelsResult : PNResult
9
10// APNS enabled channels audit request processed information.
11@property (nonatomic, readonly, strong) PNAPNSEnabledChannelsData *data;
12
13@end

Error response which is used in case of APNS List Devices API call failure:

1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
show all 16 lines

Remove device from channel

Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Disable mobile push notifications on a provided set of channels.

Method(s)

To run Removing Device From Channel, you can use the following method(s) in the Objective-C SDK:

1- (void)removePushNotificationsFromChannels:(NSArray<NSString *> *)channels 
2 withDevicePushToken:(NSData *)pushToken
3 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
* required
ParameterDescription
channels *
Type: NSArray
Channels to disable for push notifications. If empty, disables all.
pushToken *
Type: NSData
Device push token.
block
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block with request status.
1- (void)removePushNotificationsFromChannels:(NSArray<NSString *> *)channels 
2 withDevicePushToken:(id)pushToken
3 pushType:(PNPushType)pushType
4 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
* required
ParameterDescription
channels *
Type: NSArray<NSString *> *
Channels to disable for push notifications.
pushToken *
Type: id
Device token (NSString).
pushType *
Type: PNPushType
Accepted values:
  • PNFCMPush - Firebase Cloud Messaging (Google Cloud Messaging)
block
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block.
1- (void)removePushNotificationsFromChannels:(NSArray<NSString *> *)channels 
2 withDevicePushToken:(id)pushToken
3 pushType:(PNPushType)pushType
4 environment:(PNAPNSEnvironment)environment
5 topic:(NSString *)topic
6 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
* required
ParameterDescription
channels *
Type: NSArray<NSString *> *
Channels to disable for push notifications.
pushToken *
Type: id
Device token (NSData).
pushType *
Type: PNPushType
Accepted values:
  • PNAPNS2Push - Apple Push Notification service over HTTP/2
environment *
Type: PNAPNSEnvironment
APNs environment (APNS2 only).
topic *
Type: NSString
APNs topic (bundle identifier).
block
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block.

Sample code

Remove device from channel

1[self.client removePushNotificationsFromChannels:@[@"wwdc",@"google.io"]
2 withDevicePushToken:self.devicePushToken
3 andCompletion:^(PNAcknowledgmentStatus *status) {
4
5 if (!status.isError) {
6
7 // Handle successful push notification disabling on passed channels.
8 }
9 else {
10
11 /**
12 Handle modification error. Check 'category' property
13 to find out possible reason because of which request did fail.
14 Review 'errorData' property (which has PNErrorData data type) of status
15 object to get additional information about issue.
show all 20 lines

Response

Response objects returned by the client when the APNS Remove Device API is used:

1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
show all 16 lines

Other examples

  1. Example for method no. 2

    1[self.client removePushNotificationsFromChannels:@[@"wwdc",@"google.io"]
    2 withDevicePushToken:self.devicePushToken
    3 pushType:PNFCMPush
    4 andCompletion:^(PNAcknowledgmentStatus *status) {
    5
    6 if (!status.isError) {
    7 // Push notification successfully disabled on passed channels.
    8 } else {
    9 /**
    10 * Handle modification error. Check 'category' property to find out possible issue because
    11 * of which request did fail.
    12 *
    13 * Request can be resent using: [status retry];
    14 */
    15 }
    show all 16 lines
  2. Example for method no. 3

    1[self.client removePushNotificationsFromChannels:@[@"wwdc",@"google.io"]
    2 withDevicePushToken:self.devicePushToken
    3 pushType:PNAPNS2Push
    4 environment:PNAPNSProduction
    5 topic:@"com.my-application.bundle"
    6 andCompletion:^(PNAcknowledgmentStatus *status) {
    7
    8 if (!status.isError) {
    9 // Push notification successfully disabled on passed channels.
    10 } else {
    11 /**
    12 * Handle modification error. Check 'category' property to find out possible issue because
    13 * of which request did fail.
    14 *
    15 * Request can be resent using: [status retry];
    show all 18 lines

Remove a device from push notifications channels (builder pattern)

note
Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

Disable mobile push notifications on a set of channels.

Method(s)

Use the following builder methods:

APNS2 token

1push()
2 .disable()
3 .channels(NSArray<NSString *> *)
4 .token(id)
5 .pushType(PNPushType)
6 .environment(PNAPNSEnvironment)
7 .topic(NSString *)
8 .performWithCompletion(nullable PNPushNotificationsStateModificationCompletionBlock);
* required
ParameterDescription
channels *
Type: NSArray<NSString *> *
Channels to disable for push notifications.
token *
Type: id
Device token (NSData).
pushType *
Type: PNPushType
Accepted values:
  • PNAPNS2Push - Apple Push Notification service over HTTP/2
environment
Type: PNAPNSEnvironment
APNs environment (APNS2 only).
topic
Type: NSString
APNs topic (bundle identifier).
block
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block.
Note

This method uses the builder pattern. You can omit optional arguments.

FCM token

1push()
2 .disable()
3 .fcmToken(NSString *)
4 .channels(NSArray<NSString *> *)
5 .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock);
* required
ParameterDescription
channels *
Type: NSArray<NSString *> *
Channels to disable for push notifications. If empty, disables all.
fcmToken *
Type: NSString *
FCM device push token.
completion
Type: PNPushNotificationsStateAuditCompletionBlock
Completion block with request status.
Note

This method uses the builder pattern. You can omit optional arguments.

Sample code

APNS2 token

1self.client.push().disable()
2 .token(self.devicePushToken)
3 .channels(@[@"wwdc",@"google.io"])
4 .pushType(PNAPNS2Push)
5 .environment(PNAPNSProduction)
6 .topic(@"com.my-application.bundle")
7 .performWithCompletion(^(PNAcknowledgmentStatus *status) {
8 if (!status.isError) {
9 // Push notification successfully disabled on passed channels.
10 } else {
11 /**
12 * Handle modification error. Check 'category' property to find out possible issue because
13 * of which request did fail.
14 *
15 * Request can be resent using: [status retry];
show all 18 lines

FCM token

1self.client.push().disable()
2 .channels(@[@"channel1", @"channel2"])
3 .fcmToken(self.pushToken)
4 .performWithCompletion(^(PNAcknowledgmentStatus *status) {
5 if (!status.isError) {
6 // Handle successful push notification enabling on passed channels.
7 } else {
8 /**
9 Handle modification error. Check 'category' property
10 to find out possible reason because of which request did fail.
11 Review 'errorData' property (which has PNErrorData data type) of status
12 object to get additional information about issue.
13
14 Request can be resent using: [status retry];
15 */
show all 17 lines

Response

Response objects returned by the client when the APNS Remove Device API is used:

1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
show all 16 lines

Remove a device from all push notifications channels (builder pattern)

Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Disable mobile push notifications from all channels registered with the specified pushToken.

Method(s)

To run Remove all mobile push notifications, you can use the following method(s) in the Objective-C SDK:

1- (void)removeAllPushNotificationsFromDeviceWithPushToken:(NSData *)pushToken 
2 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block
* required
ParameterDescription
pushToken *
Type: NSData
Device push token which should be used to disable push notifications on a specified set of channels.
block
Type: PNPushNotificationsStateModificationCompletionBlock
Push notifications removal from device processing completion block which pass only one argument - request processing status to report about how data pushing was successful or not.
1- (void)removeAllPushNotificationsFromDeviceWithPushToken:(id)pushToken 
2 pushType:(PNPushType)pushType
3 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
* required
ParameterDescription
pushToken *
Type: id
Device token / identifier that you must set to NSString.
pushType *
Type: PNPushType
One of PNPushType fields which specify service to manage notifications for device specified with pushToken.
Available push types:
  • PNFCMPush - Firebase Cloud Messaging (Google Cloud Messaging)
block
Type: PNPushNotificationsStateModificationCompletionBlock
Remove all notifications request completion block.
1- (void)removeAllPushNotificationsFromDeviceWithPushToken:(id)pushToken 
2 pushType:(PNPushType)pushType
3 environment:(PNAPNSEnvironment)environment
4 topic:(NSString *)topic
5 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
* required
ParameterDescription
channels *
Type: NSArray<NSString *> *
List of channel names for which mobile push notifications should be disabled.
pushToken *
Type: id
Device token / identifier that you must set to NSData.
pushType *
Type: PNPushType
One of PNPushType fields which specify service to manage notifications for device specified with pushToken.
Available push types:
  • PNAPNS2Push - Apple Push Notification service over HTTP/2
environment *
Type: PNAPNSEnvironment
One of PNAPNSEnvironment fields which specify environment within which device should manage list of channels with enabled notifications (works only if pushType set to PNAPNS2Push).
topic *
Type: NSString
Notifications topic name (usually it is application's bundle identifier).
block
Type: PNPushNotificationsStateModificationCompletionBlock
Remove all notifications request completion block.

Sample code

Remove all mobile push notifications

1[self.client removeAllPushNotificationsFromDeviceWithPushToken:self.devicePushToken
2 andCompletion:^(PNAcknowledgmentStatus *status) {
3
4 if (!status.isError) {
5
6 /**
7 Handle successful push notification disabling for all channels associated with
8 specified device push token.
9 */
10 }
11 else {
12
13 /**
14 Handle modification error. Check 'category' property
15 to find out possible reason because of which request did fail.
show all 22 lines

Response

Response objects returned by the client when the APNS Remove All Devices API is used:

1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
show all 16 lines

Other examples

  1. Example for method no. 2.

    1[self.client removeAllPushNotificationsFromDeviceWithPushToken:self.devicePushToken
    2 pushType:PNFCMPush
    3 andCompletion:^(PNAcknowledgmentStatus *status) {
    4
    5 if (!status.isError) {
    6 /**
    7 * Push notification successfully disabled for all channels associated with specified
    8 * device push token.
    9 */
    10 } else {
    11 /**
    12 * Handle modification error. Check 'category' property to find out possible issue because
    13 * of which request did fail.
    14 *
    15 * Request can be resent using: [status retry];
    show all 18 lines
  2. Example for method no. 3

    1[self.client removeAllPushNotificationsFromDeviceWithPushToken:self.devicePushToken
    2 pushType:PNAPNS2Push
    3 environment:PNAPNSProduction
    4 topic:@"com.my-application.bundle"
    5 andCompletion:^(PNAcknowledgmentStatus *status) {
    6
    7 if (!status.isError) {
    8 /**
    9 * Push notification successfully disabled for all channels associated with specified
    10 * device push token.
    11 */
    12 } else {
    13 /**
    14 * Handle modification error. Check 'category' property to find out possible issue because
    15 * of which request did fail.
    show all 20 lines

Remove all mobile push notifications (builder pattern)

Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Method(s)

1push()
2 .disableAll()
3 .token(id)
4 .pushType(PNPushType)
5 .environment(PNAPNSEnvironment)
6 .topic(NSString *)
7 .performWithCompletion(nullable PNPushNotificationsStateModificationCompletionBlock);
* required
ParameterDescription
token *
Type: id
Device token (NSData for PNAPNS2Push, otherwise NSString).
pushType *
Type: PNPushType
Accepted values:
  • PNAPNS2Push - Apple Push Notification service over HTTP/2
  • PNFCMPush - Firebase Cloud Messaging (Google Cloud Messaging)
environment
Type: PNAPNSEnvironment
APNs environment (APNS2 only).
topic
Type: NSString
APNs topic (bundle identifier).
block
Type: PNPushNotificationsStateModificationCompletionBlock
Completion block.
Note

This method uses the builder pattern. You can omit optional arguments.

Sample code

Remove all mobile push notifications, using builder pattern (APNS2)

1self.client.push().disableAll()
2 .token(self.devicePushToken)
3 .pushType(PNAPNS2Push)
4 .environment(PNAPNSProduction)
5 .topic(@"com.my-application.bundle")
6 .performWithCompletion(^(PNAcknowledgmentStatus *status) {
7 if (!status.isError) {
8 /**
9 * Push notification successfully disabled for all channels associated with specified
10 * device push token.
11 */
12 } else {
13 /**
14 * Handle modification error. Check 'category' property to find out possible issue because
15 * of which request did fail.
show all 20 lines

Remove all mobile push notifications, using builder pattern (FCM)

1self.client.push().disableAll()
2 .token(self.devicePushToken)
3 .pushType(PNFCMPush)
4 .performWithCompletion(^(PNAcknowledgmentStatus *status) {
5 if (!status.isError) {
6 /**
7 * Push notification successfully disabled for all channels associated with specified
8 * device push token.
9 */
10 } else {
11 /**
12 * Handle modification error. Check 'category' property to find out possible issue because
13 * of which request did fail.
14 *
15 * Request can be resent using: [status retry];
show all 18 lines

Response

Response object returned by the client when the APNS Remove All Devices API is used:

1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
show all 16 lines
Last updated on