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
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;
1- (void)addPushNotificationsOnChannels:(NSArray<NSString *> *)channels
2 withDevicePushToken:(id)pushToken
3 pushType:(PNPushType)pushType
4 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)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;
channelsrequired#- Channels to enable for push notifications.
pushTokenrequired#- Device token (
NSData). pushTyperequired#- Accepted values:
PNAPNS2Push- Apple Push Notification service over HTTP/2
environmentrequired#- APNs environment (APNS2 only).
topicrequired#- APNs topic (bundle identifier).
block#- 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 linesResponse
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 linesOther examples
-
Example for method no. 2
show all 16 lines1[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 } -
Example for method no. 3
show all 18 lines1[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];
Add a device to a push notifications channel (builder pattern)
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);
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
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 linesFCM 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 linesResponse
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 linesList push notifications channels for a device (builder pattern)
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;
pushTokenrequired#- Device push token against which search on PubNub service should be performed.
blockrequired#- Push
notificationsstatus processing completionblockwhich pass two arguments: result - in case of successful request processing data field will contain results of pushnotificationsaudit operation; status - in case if an error occurred during request processing.
1- (void)pushNotificationEnabledChannelsForDeviceWithPushToken:(id)pushToken
2 pushType:(PNPushType)pushType
3 andCompletion:(PNPushNotificationsStateAuditCompletionBlock)block;
pushTokenrequired#- Device token / identifier that you must set to
NSString pushTyperequired#- One of
PNPushTypefields which specify service to manage notifications for device specified withpushToken.
Available push types:PNFCMPush- Firebase Cloud Messaging (Google Cloud Messaging)
blockrequired#Audit notifications enabled channelsrequest completion block.
1- (void)pushNotificationEnabledChannelsForDeviceWithPushToken:(id)pushToken
2 pushType:(PNPushType)pushType
3 environment:(PNAPNSEnvironment)environment
4 topic:(NSString *)topic
5 andCompletion:(PNPushNotificationsStateAuditCompletionBlock)block;
pushTokenrequired#- Device token / identifier that you must set to either
NSData(forPNAPNS2PushandPNAPNSPush) orNSStringfor other, depending on thepushTypepassed. pushTyperequired#- One of
PNPushTypefields which specify service to manage notifications for device specified withpushToken.
Available push types:PNAPNS2Push- Apple Push Notification service over HTTP/2
environmentrequired#- One of
PNAPNSEnvironmentfields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushTypeset toPNAPNS2Push). topicrequired#- Notifications topic name (usually it is application's bundle identifier).
blockrequired#Audit notifications enabled channelsrequest 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 linesResponse
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 linesOther examples
-
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}]; -
Example for method no. 3
show all 17 lines1[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 */
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. See Enable the features your app calls.
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
Note
This method uses the builder pattern. You can omit optional arguments.
FCM token
1push()
2 .audit()
3 .fcmToken(NSString *)
4 .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock);
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 linesFCM 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 linesResponse
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 linesRemove 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. See Enable the features your app calls.
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;
1- (void)removePushNotificationsFromChannels:(NSArray<NSString *> *)channels
2 withDevicePushToken:(id)pushToken
3 pushType:(PNPushType)pushType
4 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)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;
channelsrequired#- Channels to disable for push notifications.
pushTokenrequired#- Device token (
NSData). pushTyperequired#- Accepted values:
PNAPNS2Push- Apple Push Notification service over HTTP/2
environmentrequired#- APNs environment (APNS2 only).
topicrequired#- APNs topic (bundle identifier).
block#- 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 linesResponse
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 linesOther examples
-
Example for method no. 2
show all 16 lines1[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 } -
Example for method no. 3
show all 18 lines1[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];
Remove a device from push notifications channels (builder pattern)
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);
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);
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 linesFCM 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 linesResponse
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 linesRemove 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. See Enable the features your app calls.
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
pushTokenrequired#- Device push token which should be used to disable push
notificationson a specified set ofchannels. block#- Push
notificationsremoval from device processing completionblockwhich pass only one argument - request processingstatusto report about how data pushing was successful or not.
1- (void)removeAllPushNotificationsFromDeviceWithPushToken:(id)pushToken
2 pushType:(PNPushType)pushType
3 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
pushTokenrequired#- Device token / identifier that you must set to
NSString. pushTyperequired#- One of
PNPushTypefields which specify service to manage notifications for device specified withpushToken.
Available push types:PNFCMPush- Firebase Cloud Messaging (Google Cloud Messaging)
block#Remove all notificationsrequest completion block.
1- (void)removeAllPushNotificationsFromDeviceWithPushToken:(id)pushToken
2 pushType:(PNPushType)pushType
3 environment:(PNAPNSEnvironment)environment
4 topic:(NSString *)topic
5 andCompletion:(nullable PNPushNotificationsStateModificationCompletionBlock)block;
channelsrequired#- List of channel names for which mobile push notifications should be disabled.
pushTokenrequired#- Device token / identifier that you must set to
NSData. pushTyperequired#- One of
PNPushTypefields which specify service to manage notifications for device specified withpushToken.
Available push types:PNAPNS2Push- Apple Push Notification service over HTTP/2
environmentrequired#- One of
PNAPNSEnvironmentfields which specify environment within which device should manage list of channels with enabled notifications (works only ifpushTypeset toPNAPNS2Push). topicrequired#- Notifications topic name (usually it is application's bundle identifier).
block#Remove all notificationsrequest 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 linesResponse
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 linesOther examples
-
Example for method no. 2.
show all 18 lines1[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]; -
Example for method no. 3
show all 20 lines1[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.
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. See Enable the features your app calls.
Method(s)
1push()
2 .disableAll()
3 .token(id)
4 .pushType(PNPushType)
5 .environment(PNAPNSEnvironment)
6 .topic(NSString *)
7 .performWithCompletion(nullable PNPushNotificationsStateModificationCompletionBlock);
tokenrequired#- Device token (
NSDataforPNAPNS2Push, otherwiseNSString). pushTyperequired#- Accepted values:
PNAPNS2Push- Apple Push Notification service over HTTP/2PNFCMPush- Firebase Cloud Messaging (Google Cloud Messaging)
environment#- APNs environment (APNS2 only).
topic#- APNs topic (bundle identifier).
block#- 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 linesRemove 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 linesResponse
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