PFPush

@interface PFPush : NSObject <NSCopying>

The PFPush class defines a push notification that can be sent from a client device.

The preferred way of modifying or retrieving channel subscriptions is to use the PFInstallation class, instead of the class methods in PFPush.


  • Declaration

    Objective-C

    + (nonnull instancetype)push;
  • Sets the channel on which this push notification will be sent.

    Declaration

    Objective-C

    - (void)setChannel:(nullable NSString *)channel;

    Parameters

    channel

    The channel to set for this push. The channel name must start with a letter and contain only letters, numbers, dashes, and underscores.

  • Sets the array of channels on which this push notification will be sent.

    Declaration

    Objective-C

    - (void)setChannels:(nullable NSArray<NSString *> *)channels;

    Parameters

    channels

    The array of channels to set for this push. Each channel name must start with a letter and contain only letters, numbers, dashes, and underscores.

  • Sets an installation query to which this push notification will be sent.

    The query should be created via PFInstallation.+query and should not specify a skip, limit, or order.

    Declaration

    Objective-C

    - (void)setQuery:(nullable PFQuery<PFInstallation *> *)query;

    Parameters

    query

    The installation query to set for this push.

  • Sets an alert message for this push notification.

    Warning

    This will overwrite any data specified in setData.

    Declaration

    Objective-C

    - (void)setMessage:(nullable NSString *)message;

    Parameters

    message

    The message to send in this push.

  • Sets an arbitrary data payload for this push notification.

    See the guide for information about the dictionary structure.

    Warning

    This will overwrite any data specified in setMessage.

    Declaration

    Objective-C

    - (void)setData:(nullable NSDictionary *)data;

    Parameters

    data

    The data to send in this push.

  • Sets whether this push will go to Android devices.

    @deprecated Please use a PFInstallation.+query with a constraint on deviceType instead.

    Declaration

    Objective-C

    - (void)setPushToAndroid:(BOOL)pushToAndroid;

    Parameters

    pushToAndroid

    Whether this push will go to Android devices.

  • Sets whether this push will go to iOS devices.

    @deprecated Please use a PFInstallation.+query with a constraint on deviceType instead.

    Declaration

    Objective-C

    - (void)setPushToIOS:(BOOL)pushToIOS;

    Parameters

    pushToIOS

    Whether this push will go to iOS devices.

  • Sets the expiration time for this notification.

    The notification will be sent to devices which are either online at the time the notification is sent, or which come online before the expiration time is reached. Because device clocks are not guaranteed to be accurate, most applications should instead use -expireAfterTimeInterval:.

    See

    expireAfterTimeInterval:

    Declaration

    Objective-C

    - (void)expireAtDate:(nullable NSDate *)date;

    Parameters

    date

    The time at which the notification should expire.

  • Sets the time interval after which this notification should expire.

    This notification will be sent to devices which are either online at the time the notification is sent, or which come online within the given time interval of the notification being received by Parse’s server. An interval which is less than or equal to zero indicates that the message should only be sent to devices which are currently online.

    Declaration

    Objective-C

    - (void)expireAfterTimeInterval:(NSTimeInterval)timeInterval;

    Parameters

    timeInterval

    The interval after which the notification should expire.

  • Clears both expiration values, indicating that the notification should never expire.

    Declaration

    Objective-C

    - (void)clearExpiration;
  • Date at which to send this push notification.

    Push notificaitons with this date will be delivered at the local time matching the PFInstallation.timeZone.

    Warning

    The date cannot be in the past, and can be up to two weeks in the future.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) NSDate *pushDate;
  • Asynchronously send a push message to a channel.

    Declaration

    Objective-C

    + (id)sendPushMessageToChannelInBackground:(nonnull NSString *)channel
                                   withMessage:(nonnull NSString *)message;

    Parameters

    channel

    The channel to send to. The channel name must start with a letter and contain only letters, numbers, dashes, and underscores.

    message

    The message to send.

    Return Value

    The task, that encapsulates the work being done.

  • Asynchronously sends a push message to a channel and calls the given block.

    Declaration

    Objective-C

    + (void)sendPushMessageToChannelInBackground:(nonnull NSString *)channel
                                     withMessage:(nonnull NSString *)message
                                           block:
                                               (nullable PFBooleanResultBlock)block;

    Parameters

    channel

    The channel to send to. The channel name must start with a letter and contain only letters, numbers, dashes, and underscores.

    message

    The message to send.

    block

    The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error)

  • Asynchronously send a push message to a query.

    Declaration

    Objective-C

    + (id)sendPushMessageToQueryInBackground:
              (nonnull PFQuery<PFInstallation *> *)query
                                 withMessage:(nonnull NSString *)message;

    Parameters

    query

    The query to send to. The query must be a PFInstallation query created with PFInstallation.+query.

    message

    The message to send.

    Return Value

    The task, that encapsulates the work being done.

  • Asynchronously sends a push message to a query and calls the given block.

    Declaration

    Objective-C

    + (void)sendPushMessageToQueryInBackground:
                (nonnull PFQuery<PFInstallation *> *)query
                                   withMessage:(nonnull NSString *)message
                                         block:(nullable PFBooleanResultBlock)block;

    Parameters

    query

    The query to send to. The query must be a PFInstallation query created with [PFInstallation query].

    message

    The message to send.

    block

    The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error)

  • Asynchronously send this push message. - returns: The task, that encapsulates the work being done.

    Declaration

    Objective-C

    - (id)sendPushInBackground;

    Return Value

    The task, that encapsulates the work being done.

  • Asynchronously send this push message and executes the given callback block.

    Declaration

    Objective-C

    - (void)sendPushInBackgroundWithBlock:(nullable PFBooleanResultBlock)block;

    Parameters

    block

    The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error).

  • Asynchronously send a push message with arbitrary data to a channel.

    See the guide for information about the dictionary structure.

    Declaration

    Objective-C

    + (id)sendPushDataToChannelInBackground:(nonnull NSString *)channel
                                   withData:(nonnull NSDictionary *)data;

    Parameters

    channel

    The channel to send to. The channel name must start with a letter and contain only letters, numbers, dashes, and underscores.

    data

    The data to send.

    Return Value

    The task, that encapsulates the work being done.

  • Asynchronously sends a push message with arbitrary data to a channel and calls the given block.

    See the guide for information about the dictionary structure.

    Declaration

    Objective-C

    + (void)sendPushDataToChannelInBackground:(nonnull NSString *)channel
                                     withData:(nonnull NSDictionary *)data
                                        block:(nullable PFBooleanResultBlock)block;

    Parameters

    channel

    The channel to send to. The channel name must start with a letter and contain only letters, numbers, dashes, and underscores.

    data

    The data to send.

    block

    The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error).

  • Asynchronously send a push message with arbitrary data to a query.

    See the guide for information about the dictionary structure.

    Declaration

    Objective-C

    + (id)sendPushDataToQueryInBackground:(nonnull PFQuery<PFInstallation *> *)query
                                 withData:(nonnull NSDictionary *)data;

    Parameters

    query

    The query to send to. The query must be a PFInstallation query created with PFInstallation.+query.

    data

    The data to send.

    Return Value

    The task, that encapsulates the work being done.

  • Asynchronously sends a push message with arbitrary data to a query and calls the given block.

    See the guide for information about the dictionary structure.

    Declaration

    Objective-C

    + (void)sendPushDataToQueryInBackground:
                (nonnull PFQuery<PFInstallation *> *)query
                                   withData:(nonnull NSDictionary *)data
                                      block:(nullable PFBooleanResultBlock)block;

    Parameters

    query

    The query to send to. The query must be a PFInstallation query created with PFInstallation.+query.

    data

    The data to send.

    block

    The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error).

  • A default handler for push notifications while the app is active that could be used to mimic the behavior of iOS push notifications while the app is backgrounded or not running.

    Call this from application:didReceiveRemoteNotification:. If push has a dictionary containing loc-key and loc-args in the alert, we support up to 10 items in loc-args (NSRangeException if limit exceeded).

    Warning

    This method is available only on iOS.

    Declaration

    Objective-C

    + (void)handlePush:(nullable NSDictionary *)userInfo;

    Parameters

    userInfo

    The userInfo dictionary you get in appplication:didReceiveRemoteNotification:.

  • Store the device token locally for push notifications.

    Usually called from you main app delegate’s didRegisterForRemoteNotificationsWithDeviceToken:.

    Declaration

    Objective-C

    + (void)storeDeviceToken:(nonnull id)deviceToken;

    Parameters

    deviceToken

    Either as an NSData straight from application:didRegisterForRemoteNotificationsWithDeviceToken: or as an NSString if you converted it yourself.

  • Asynchronously get all the channels that this device is subscribed to.

    Declaration

    Objective-C

    + (id)getSubscribedChannelsInBackground;

    Return Value

    The task, that encapsulates the work being done.

  • Asynchronously get all the channels that this device is subscribed to. - parameter: block The block to execute. It should have the following argument signature: ^(NSSet *channels, NSError *error).

    Declaration

    Objective-C

    + (void)getSubscribedChannelsInBackgroundWithBlock:
            (nonnull PFSetResultBlock)block;

    Parameters

    block

    The block to execute. It should have the following argument signature: ^(NSSet *channels, NSError *error).

  • Asynchronously subscribes the device to a channel of push notifications.

    Declaration

    Objective-C

    + (id)subscribeToChannelInBackground:(nonnull NSString *)channel;

    Parameters

    channel

    The channel to subscribe to. The channel name must start with a letter and contain only letters, numbers, dashes, and underscores.

    Return Value

    The task, that encapsulates the work being done.

  • Asynchronously subscribes the device to a channel of push notifications and calls the given block.

    Declaration

    Objective-C

    + (void)subscribeToChannelInBackground:(nonnull NSString *)channel
                                     block:(nullable PFBooleanResultBlock)block;

    Parameters

    channel

    The channel to subscribe to. The channel name must start with a letter and contain only letters, numbers, dashes, and underscores.

    block

    The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error)

  • Asynchronously unsubscribes the device from a channel of push notifications.

    Declaration

    Objective-C

    + (id)unsubscribeFromChannelInBackground:(nonnull NSString *)channel;

    Parameters

    channel

    The channel to unsubscribe from.

    Return Value

    The task, that encapsulates the work being done.

  • Asynchronously unsubscribes the device from a channel of push notifications and calls the given block.

    Declaration

    Objective-C

    + (void)unsubscribeFromChannelInBackground:(nonnull NSString *)channel
                                         block:(nullable PFBooleanResultBlock)block;

    Parameters

    channel

    The channel to unsubscribe from.

    block

    The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error).