/Parse.framework/Versions/1.2.19/Headers/PFPush.h

https://gitlab.com/Raemond/Confidence · C Header · 396 lines · 81 code · 50 blank · 265 comment · 0 complexity · 3736fdd5a94395670d816914b6d2f059 MD5 · raw file

  1. //
  2. // PFPush.h
  3. // Parse
  4. //
  5. // Created by Ilya Sukhar on 7/4/11.
  6. // Copyright 2011 Parse, Inc. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <AudioToolbox/AudioToolbox.h>
  10. #import "PFConstants.h"
  11. #import "PFQuery.h"
  12. /*!
  13. A class which defines a push notification that can be sent from
  14. a client device.
  15. The preferred way of modifying or retrieving channel subscriptions is to use
  16. the PFInstallation class, instead of the class methods in PFPush.
  17. This class is currently for iOS only. Parse does not handle Push Notifications
  18. to Parse applications running on OS X. Push Notifications can be sent from OS X
  19. applications via Cloud Code or the REST API to push-enabled devices (e.g. iOS
  20. or Android).
  21. */
  22. @interface PFPush : NSObject
  23. /*! @name Creating a Push Notification */
  24. + (PFPush *)push;
  25. /*! @name Configuring a Push Notification */
  26. /*!
  27. Sets the channel on which this push notification will be sent.
  28. @param channel The channel to set for this push. The channel name must start
  29. with a letter and contain only letters, numbers, dashes, and underscores.
  30. */
  31. - (void)setChannel:(NSString *)channel;
  32. /*!
  33. Sets the array of channels on which this push notification will
  34. be sent.
  35. @param channels The array of channels to set for this push. Each channel name
  36. must start with a letter and contain only letters, numbers, dashes, and underscores.
  37. */
  38. - (void)setChannels:(NSArray *)channels;
  39. /*!
  40. Sets an installation query to which this push notification will be sent. The
  41. query should be created via [PFInstallation query] and should not specify a
  42. skip, limit, or order.
  43. @param query The installation query to set for this push.
  44. */
  45. - (void)setQuery:(PFQuery *)query;
  46. /*!
  47. Sets an alert message for this push notification. This will overwrite
  48. any data specified in setData.
  49. @param message The message to send in this push.
  50. */
  51. - (void)setMessage:(NSString *)message;
  52. /*!
  53. Sets an arbitrary data payload for this push notification. See the guide
  54. for information about the dictionary structure. This will overwrite any
  55. data specified in setMessage.
  56. @param data The data to send in this push.
  57. */
  58. - (void)setData:(NSDictionary *)data;
  59. /*!
  60. Deprecated. Please use a PFInstallation.query with a constraint on deviceType.
  61. */
  62. - (void)setPushToAndroid:(BOOL)pushToAndroid __attribute__ ((deprecated));
  63. /*!
  64. Deprecated. Please use a PFInstallation.query with a constraint on deviceType.
  65. */
  66. - (void)setPushToIOS:(BOOL)pushToIOS __attribute__ ((deprecated));
  67. /*!
  68. Sets the expiration time for this notification. The notification will be
  69. sent to devices which are either online at the time the notification
  70. is sent, or which come online before the expiration time is reached.
  71. Because device clocks are not guaranteed to be accurate, most applications
  72. should instead use expireAfterTimeInterval.
  73. @param time The time at which the notification should expire.
  74. */
  75. - (void)expireAtDate:(NSDate *)date;
  76. /*!
  77. Sets the time interval after which this notification should expire.
  78. This notification will be sent to devices which are either online at
  79. the time the notification is sent, or which come online within the given
  80. time interval of the notification being received by Parse's server.
  81. An interval which is less than or equal to zero indicates that the
  82. message should only be sent to devices which are currently online.
  83. @param interval The interval after which the notification should expire.
  84. */
  85. - (void)expireAfterTimeInterval:(NSTimeInterval)timeInterval;
  86. /*!
  87. Clears both expiration values, indicating that the notification should
  88. never expire.
  89. */
  90. - (void)clearExpiration;
  91. /*! @name Sending Push Notifications */
  92. /*!
  93. Send a push message to a channel.
  94. @param channel The channel to send to. The channel name must start with
  95. a letter and contain only letters, numbers, dashes, and underscores.
  96. @param message The message to send.
  97. @param error Pointer to an NSError that will be set if necessary.
  98. @result Returns whether the send succeeded.
  99. */
  100. + (BOOL)sendPushMessageToChannel:(NSString *)channel
  101. withMessage:(NSString *)message
  102. error:(NSError **)error;
  103. /*!
  104. Asynchronously send a push message to a channel.
  105. @param channel The channel to send to. The channel name must start with
  106. a letter and contain only letters, numbers, dashes, and underscores.
  107. @param message The message to send.
  108. */
  109. + (void)sendPushMessageToChannelInBackground:(NSString *)channel
  110. withMessage:(NSString *)message;
  111. /*!
  112. Asynchronously sends a push message to a channel and calls the given block.
  113. @param channel The channel to send to. The channel name must start with
  114. a letter and contain only letters, numbers, dashes, and underscores.
  115. @param message The message to send.
  116. @param block The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)
  117. */
  118. + (void)sendPushMessageToChannelInBackground:(NSString *)channel
  119. withMessage:(NSString *)message
  120. block:(PFBooleanResultBlock)block;
  121. /*!
  122. Asynchronously send a push message to a channel.
  123. @param channel The channel to send to. The channel name must start with
  124. a letter and contain only letters, numbers, dashes, and underscores.
  125. @param message The message to send.
  126. @param target The object to call selector on.
  127. @param selector The selector to call. It should have the following signature: (void)callbackWithResult:(NSNumber *)result error:(NSError *)error. error will be nil on success and set if there was an error. [result boolValue] will tell you whether the call succeeded or not.
  128. */
  129. + (void)sendPushMessageToChannelInBackground:(NSString *)channel
  130. withMessage:(NSString *)message
  131. target:(id)target
  132. selector:(SEL)selector;
  133. /*!
  134. Send a push message to a query.
  135. @param query The query to send to. The query must be a PFInstallation query
  136. created with [PFInstallation query].
  137. @param message The message to send.
  138. @param error Pointer to an NSError that will be set if necessary.
  139. @result Returns whether the send succeeded.
  140. */
  141. + (BOOL)sendPushMessageToQuery:(PFQuery *)query
  142. withMessage:(NSString *)message
  143. error:(NSError **)error;
  144. /*!
  145. Asynchronously send a push message to a query.
  146. @param query The query to send to. The query must be a PFInstallation query
  147. created with [PFInstallation query].
  148. @param message The message to send.
  149. */
  150. + (void)sendPushMessageToQueryInBackground:(PFQuery *)query
  151. withMessage:(NSString *)message;
  152. /*!
  153. Asynchronously sends a push message to a query and calls the given block.
  154. @param query The query to send to. The query must be a PFInstallation query
  155. created with [PFInstallation query].
  156. @param message The message to send.
  157. @param block The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)
  158. */
  159. + (void)sendPushMessageToQueryInBackground:(PFQuery *)query
  160. withMessage:(NSString *)message
  161. block:(PFBooleanResultBlock)block;
  162. /*!
  163. Send this push message.
  164. @param error Pointer to an NSError that will be set if necessary.
  165. @result Returns whether the send succeeded.
  166. */
  167. - (BOOL)sendPush:(NSError **)error;
  168. /*!
  169. Asynchronously send this push message.
  170. */
  171. - (void)sendPushInBackground;
  172. /*!
  173. Asynchronously send this push message and executes the given callback block.
  174. @param block The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)
  175. */
  176. - (void)sendPushInBackgroundWithBlock:(PFBooleanResultBlock)block;
  177. /*!
  178. Asynchronously send this push message and calls the given callback.
  179. @param target The object to call selector on.
  180. @param selector The selector to call. It should have the following signature: (void)callbackWithResult:(NSNumber *)result error:(NSError *)error. error will be nil on success and set if there was an error. [result boolValue] will tell you whether the call succeeded or not.
  181. */
  182. - (void)sendPushInBackgroundWithTarget:(id)target selector:(SEL)selector;
  183. /*!
  184. Send a push message with arbitrary data to a channel. See the guide for information about the dictionary structure.
  185. @param channel The channel to send to. The channel name must start with
  186. a letter and contain only letters, numbers, dashes, and underscores.
  187. @param data The data to send.
  188. @param error Pointer to an NSError that will be set if necessary.
  189. @result Returns whether the send succeeded.
  190. */
  191. + (BOOL)sendPushDataToChannel:(NSString *)channel
  192. withData:(NSDictionary *)data
  193. error:(NSError **)error;
  194. /*!
  195. Asynchronously send a push message with arbitrary data to a channel. See the guide for information about the dictionary structure.
  196. @param channel The channel to send to. The channel name must start with
  197. a letter and contain only letters, numbers, dashes, and underscores.
  198. @param data The data to send.
  199. */
  200. + (void)sendPushDataToChannelInBackground:(NSString *)channel
  201. withData:(NSDictionary *)data;
  202. /*!
  203. 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.
  204. @param channel The channel to send to. The channel name must start with
  205. a letter and contain only letters, numbers, dashes, and underscores.
  206. @param data The data to send.
  207. @param block The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)
  208. */
  209. + (void)sendPushDataToChannelInBackground:(NSString *)channel
  210. withData:(NSDictionary *)data
  211. block:(PFBooleanResultBlock)block;
  212. /*!
  213. Asynchronously send a push message with arbitrary data to a channel. See the guide for information about the dictionary structure.
  214. @param channel The channel to send to. The channel name must start with
  215. a letter and contain only letters, numbers, dashes, and underscores.
  216. @param data The data to send.
  217. @param target The object to call selector on.
  218. @param selector The selector to call. It should have the following signature: (void)callbackWithResult:(NSNumber *)result error:(NSError *)error. error will be nil on success and set if there was an error. [result boolValue] will tell you whether the call succeeded or not.
  219. */
  220. + (void)sendPushDataToChannelInBackground:(NSString *)channel
  221. withData:(NSDictionary *)data
  222. target:(id)target
  223. selector:(SEL)selector;
  224. /*!
  225. Send a push message with arbitrary data to a query. See the guide for information about the dictionary structure.
  226. @param query The query to send to. The query must be a PFInstallation query
  227. created with [PFInstallation query].
  228. @param data The data to send.
  229. @param error Pointer to an NSError that will be set if necessary.
  230. @result Returns whether the send succeeded.
  231. */
  232. + (BOOL)sendPushDataToQuery:(PFQuery *)query
  233. withData:(NSDictionary *)data
  234. error:(NSError **)error;
  235. /*!
  236. Asynchronously send a push message with arbitrary data to a query. See the guide for information about the dictionary structure.
  237. @param query The query to send to. The query must be a PFInstallation query
  238. created with [PFInstallation query].
  239. @param data The data to send.
  240. */
  241. + (void)sendPushDataToQueryInBackground:(PFQuery *)query
  242. withData:(NSDictionary *)data;
  243. /*!
  244. 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.
  245. @param query The query to send to. The query must be a PFInstallation query
  246. created with [PFInstallation query].
  247. @param data The data to send.
  248. @param block The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)
  249. */
  250. + (void)sendPushDataToQueryInBackground:(PFQuery *)query
  251. withData:(NSDictionary *)data
  252. block:(PFBooleanResultBlock)block;
  253. /*! @name Handling Notifications */
  254. /*!
  255. A default handler for push notifications while the app is active to mimic the behavior of iOS push notifications while the app is backgrounded or not running. Call this from didReceiveRemoteNotification.
  256. @param userInfo The userInfo dictionary you get in didReceiveRemoteNotification.
  257. */
  258. + (void)handlePush:(NSDictionary *)userInfo;
  259. /*! @name Managing Channel Subscriptions */
  260. /*!
  261. Store the device token locally for push notifications. Usually called from you main app delegate's didRegisterForRemoteNotificationsWithDeviceToken.
  262. @param deviceToken Either as an NSData straight from didRegisterForRemoteNotificationsWithDeviceToken or as an NSString if you converted it yourself.
  263. */
  264. + (void)storeDeviceToken:(id)deviceToken;
  265. /*!
  266. Get all the channels that this device is subscribed to.
  267. @param error Pointer to an NSError that will be set if necessary.
  268. @result Returns an NSSet containing all the channel names this device is subscribed to.
  269. */
  270. + (NSSet *)getSubscribedChannels:(NSError **)error;
  271. /*!
  272. Get all the channels that this device is subscribed to.
  273. @param block The block to execute. The block should have the following argument signature: (NSSet *channels, NSError *error)
  274. */
  275. + (void)getSubscribedChannelsInBackgroundWithBlock:(PFSetResultBlock)block;
  276. /*!
  277. Asynchronously get all the channels that this device is subscribed to.
  278. @param target The object to call selector on.
  279. @param selector The selector to call. It should have the following signature: (void)callbackWithResult:(NSSet *)result error:(NSError *)error. error will be nil on success and set if there was an error.
  280. @result Returns an NSSet containing all the channel names this device is subscribed to.
  281. */
  282. + (void)getSubscribedChannelsInBackgroundWithTarget:(id)target
  283. selector:(SEL)selector;
  284. /*!
  285. Subscribes the device to a channel of push notifications.
  286. @param channel The channel to subscribe to. The channel name must start with
  287. a letter and contain only letters, numbers, dashes, and underscores.
  288. @param error Pointer to an NSError that will be set if necessary.
  289. @result Returns whether the subscribe succeeded.
  290. */
  291. + (BOOL)subscribeToChannel:(NSString *)channel error:(NSError **)error;
  292. /*!
  293. Asynchronously subscribes the device to a channel of push notifications.
  294. @param channel The channel to subscribe to. The channel name must start with
  295. a letter and contain only letters, numbers, dashes, and underscores.
  296. */
  297. + (void)subscribeToChannelInBackground:(NSString *)channel;
  298. /*!
  299. Asynchronously subscribes the device to a channel of push notifications and calls the given block.
  300. @param channel The channel to subscribe to. The channel name must start with
  301. a letter and contain only letters, numbers, dashes, and underscores.
  302. @param block The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)
  303. */
  304. + (void)subscribeToChannelInBackground:(NSString *)channel
  305. block:(PFBooleanResultBlock)block;
  306. /*!
  307. Asynchronously subscribes the device to a channel of push notifications and calls the given callback.
  308. @param channel The channel to subscribe to. The channel name must start with
  309. a letter and contain only letters, numbers, dashes, and underscores.
  310. @param target The object to call selector on.
  311. @param selector The selector to call. It should have the following signature: (void)callbackWithResult:(NSNumber *)result error:(NSError *)error. error will be nil on success and set if there was an error. [result boolValue] will tell you whether the call succeeded or not.
  312. */
  313. + (void)subscribeToChannelInBackground:(NSString *)channel
  314. target:(id)target
  315. selector:(SEL)selector;
  316. /*!
  317. Unsubscribes the device to a channel of push notifications.
  318. @param channel The channel to unsubscribe from.
  319. @param error Pointer to an NSError that will be set if necessary.
  320. @result Returns whether the unsubscribe succeeded.
  321. */
  322. + (BOOL)unsubscribeFromChannel:(NSString *)channel error:(NSError **)error;
  323. /*!
  324. Asynchronously unsubscribes the device from a channel of push notifications.
  325. @param channel The channel to unsubscribe from.
  326. */
  327. + (void)unsubscribeFromChannelInBackground:(NSString *)channel;
  328. /*!
  329. Asynchronously unsubscribes the device from a channel of push notifications and calls the given block.
  330. @param channel The channel to unsubscribe from.
  331. @param block The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)
  332. */
  333. + (void)unsubscribeFromChannelInBackground:(NSString *)channel
  334. block:(PFBooleanResultBlock)block;
  335. /*!
  336. Asynchronously unsubscribes the device from a channel of push notifications and calls the given callback.
  337. @param channel The channel to unsubscribe from.
  338. @param target The object to call selector on.
  339. @param selector The selector to call. It should have the following signature: (void)callbackWithResult:(NSNumber *)result error:(NSError *)error. error will be nil on success and set if there was an error. [result boolValue] will tell you whether the call succeeded or not.
  340. */
  341. + (void)unsubscribeFromChannelInBackground:(NSString *)channel
  342. target:(id)target
  343. selector:(SEL)selector;
  344. @end