FBWebDialogs.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright 2010-present Facebook.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <UIKit/UIKit.h>
  17. @class FBFrictionlessRecipientCache;
  18. @class FBSession;
  19. @protocol FBWebDialogsDelegate;
  20. /*!
  21. @typedef NS_ENUM (NSUInteger, FBWebDialogResult)
  22. @abstract
  23. Passed to a handler to indicate the result of a dialog being displayed to the user.
  24. @discussion Note `FBWebDialogResultDialogCompleted` is also used for cancelled operations.
  25. */
  26. typedef NS_ENUM(NSUInteger, FBWebDialogResult) {
  27. /*! Indicates that the dialog action completed successfully. Note, that cancel operations represent completed dialog operations.
  28. The url argument may be used to distinguish between success and user-cancelled cases */
  29. FBWebDialogResultDialogCompleted = 0,
  30. /*! Indicates that the dialog operation was not completed. This occurs in cases such as the closure of the web-view using the X in the upper left corner. */
  31. FBWebDialogResultDialogNotCompleted
  32. };
  33. /*!
  34. @typedef
  35. @abstract Defines a handler that will be called in response to the web dialog
  36. being dismissed
  37. */
  38. typedef void (^FBWebDialogHandler)(
  39. FBWebDialogResult result,
  40. NSURL *resultURL,
  41. NSError *error);
  42. /*!
  43. @class FBWebDialogs
  44. @abstract
  45. Provides methods to display web based dialogs to the user.
  46. */
  47. @interface FBWebDialogs : NSObject
  48. /*!
  49. @abstract
  50. Presents a Facebook web dialog (https://developers.facebook.com/docs/reference/dialogs/ )
  51. such as feed or apprequest.
  52. @param session Represents the session to use for the dialog. May be nil, which uses
  53. the active session if present, or returns NO, if not.
  54. @param dialog Represents the dialog or method name, such as @"feed"
  55. @param parameters A dictionary of parameters to be passed to the dialog
  56. @param handler An optional handler that will be called when the dialog is dismissed. Note,
  57. that if the method returns NO, the handler is not called. May be nil.
  58. */
  59. + (void)presentDialogModallyWithSession:(FBSession *)session
  60. dialog:(NSString *)dialog
  61. parameters:(NSDictionary *)parameters
  62. handler:(FBWebDialogHandler)handler;
  63. /*!
  64. @abstract
  65. Presents a Facebook web dialog (https://developers.facebook.com/docs/reference/dialogs/ )
  66. such as feed or apprequest.
  67. @param session Represents the session to use for the dialog. May be nil, which uses
  68. the active session if present, or returns NO, if not.
  69. @param dialog Represents the dialog or method name, such as @"feed"
  70. @param parameters A dictionary of parameters to be passed to the dialog
  71. @param handler An optional handler that will be called when the dialog is dismissed. Note,
  72. that if the method returns NO, the handler is not called. May be nil.
  73. @param delegate An optional delegate to allow for advanced processing of web based
  74. dialogs. See 'FBWebDialogsDelegate' for more details.
  75. */
  76. + (void)presentDialogModallyWithSession:(FBSession *)session
  77. dialog:(NSString *)dialog
  78. parameters:(NSDictionary *)parameters
  79. handler:(FBWebDialogHandler)handler
  80. delegate:(id<FBWebDialogsDelegate>)delegate;
  81. /*!
  82. @abstract
  83. Presents a Facebook apprequest dialog.
  84. @param session Represents the session to use for the dialog. May be nil, which uses
  85. the active session if present.
  86. @param message The required message for the dialog.
  87. @param title An optional title for the dialog.
  88. @param parameters A dictionary of additional parameters to be passed to the dialog. May be nil
  89. @param handler An optional handler that will be called when the dialog is dismissed. May be nil.
  90. */
  91. + (void)presentRequestsDialogModallyWithSession:(FBSession *)session
  92. message:(NSString *)message
  93. title:(NSString *)title
  94. parameters:(NSDictionary *)parameters
  95. handler:(FBWebDialogHandler)handler;
  96. /*!
  97. @abstract
  98. Presents a Facebook apprequest dialog.
  99. @param session Represents the session to use for the dialog. May be nil, which uses
  100. the active session if present.
  101. @param message The required message for the dialog.
  102. @param title An optional title for the dialog.
  103. @param parameters A dictionary of additional parameters to be passed to the dialog. May be nil
  104. @param handler An optional handler that will be called when the dialog is dismissed. May be nil.
  105. @param friendCache An optional cache object used to enable frictionless sharing for a known set of friends. The
  106. cache instance should be preserved for the life of the session and reused for multiple calls to the present method.
  107. As the users set of friends enabled for frictionless sharing changes, this method auto-updates the cache.
  108. */
  109. + (void)presentRequestsDialogModallyWithSession:(FBSession *)session
  110. message:(NSString *)message
  111. title:(NSString *)title
  112. parameters:(NSDictionary *)parameters
  113. handler:(FBWebDialogHandler)handler
  114. friendCache:(FBFrictionlessRecipientCache *)friendCache;
  115. /*!
  116. @abstract
  117. Presents a Facebook feed dialog.
  118. @param session Represents the session to use for the dialog. May be nil, which uses
  119. the active session if present.
  120. @param parameters A dictionary of additional parameters to be passed to the dialog. May be nil
  121. @param handler An optional handler that will be called when the dialog is dismissed. May be nil.
  122. */
  123. + (void)presentFeedDialogModallyWithSession:(FBSession *)session
  124. parameters:(NSDictionary *)parameters
  125. handler:(FBWebDialogHandler)handler;
  126. @end
  127. /*!
  128. @protocol
  129. @abstract
  130. The `FBWebDialogsDelegate` protocol enables the plugging of advanced behaviors into
  131. the presentation flow of a Facebook web dialog. Advanced uses include modification
  132. of parameters and application-level handling of links on the dialog. The
  133. `FBFrictionlessRequestFriendCache` class implements this protocol to add frictionless
  134. behaviors to a presentation of the request dialog.
  135. */
  136. @protocol FBWebDialogsDelegate<NSObject>
  137. @optional
  138. /*!
  139. @abstract
  140. Called prior to the presentation of a web dialog
  141. @param dialog A string representing the method or dialog name of the dialog being presented.
  142. @param parameters A mutable dictionary of parameters which will be sent to the dialog.
  143. @param session The session object to use with the dialog.
  144. */
  145. - (void)webDialogsWillPresentDialog:(NSString *)dialog
  146. parameters:(NSMutableDictionary *)parameters
  147. session:(FBSession *)session;
  148. /*!
  149. @abstract
  150. Called when the user of a dialog clicks a link that would cause a transition away from the application.
  151. Your application may handle this method, and return NO if the URL handling will be performed by the application.
  152. @param dialog A string representing the method or dialog name of the dialog being presented.
  153. @param parameters A dictionary of parameters which were sent to the dialog.
  154. @param session The session object to use with the dialog.
  155. @param url The url in question, which will not be handled by the SDK if this method NO
  156. */
  157. - (BOOL)webDialogsDialog:(NSString *)dialog
  158. parameters:(NSDictionary *)parameters
  159. session:(FBSession *)session
  160. shouldAutoHandleURL:(NSURL *)url;
  161. /*!
  162. @abstract
  163. Called when the dialog is about to be dismissed
  164. @param dialog A string representing the method or dialog name of the dialog being presented.
  165. @param parameters A dictionary of parameters which were sent to the dialog.
  166. @param session The session object to use with the dialog.
  167. @param result A pointer to a result, which may be read or changed by the handling method as needed
  168. @param url A pointer to a pointer to a URL representing the URL returned by the dialog, which may be read or changed by this mehthod
  169. @param error A pointer to a pointer to an error object which may be read or changed by this method as needed
  170. */
  171. - (void)webDialogsWillDismissDialog:(NSString *)dialog
  172. parameters:(NSDictionary *)parameters
  173. session:(FBSession *)session
  174. result:(FBWebDialogResult *)result
  175. url:(NSURL **)url
  176. error:(NSError **)error;
  177. @end