FBAppCall.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 <Foundation/Foundation.h>
  17. #import "FBAccessTokenData.h"
  18. #import "FBAppLinkData.h"
  19. #import "FBDialogsData.h"
  20. #import "FBSession.h"
  21. @class FBAppCall;
  22. /*!
  23. @typedef FBAppCallHandler
  24. @abstract
  25. A block that is passed to performAppCall to register for a callback with the results
  26. of that AppCall
  27. @discussion
  28. Pass a block of this type when calling performAppCall. This will be called on the UI
  29. thread, once the AppCall completes.
  30. @param call The `FBAppCall` that was completed.
  31. */
  32. typedef void (^FBAppCallHandler)(FBAppCall *call);
  33. /*!
  34. @typedef FBAppLinkFallbackHandler
  35. @abstract
  36. See `+openDeferredAppLink`.
  37. */
  38. typedef void (^FBAppLinkFallbackHandler)(NSError *error);
  39. /*!
  40. @class FBAppCall
  41. @abstract
  42. The FBAppCall object is used to encapsulate state when the app performs an
  43. action that requires switching over to the native Facebook app, or when the app
  44. receives an App Link.
  45. @discussion
  46. - Each FBAppCall instance will have a unique ID
  47. - This object is passed into an FBAppCallHandler for context
  48. - dialogData will be present if this AppCall is for a Native Dialog
  49. - appLinkData will be present if this AppCall is for an App Link
  50. - accessTokenData will be present if this AppCall contains an access token.
  51. */
  52. @interface FBAppCall : NSObject
  53. /*! @abstract The ID of this FBAppCall instance */
  54. @property (nonatomic, readonly) NSString *ID;
  55. /*! @abstract Error that occurred in processing this AppCall */
  56. @property (nonatomic, readonly) NSError *error;
  57. /*! @abstract Data related to a Dialog AppCall */
  58. @property (nonatomic, readonly) FBDialogsData *dialogData;
  59. /*! @abstract Data for native app link */
  60. @property (nonatomic, readonly) FBAppLinkData *appLinkData;
  61. /*! @abstract Access Token that was returned in this AppCall */
  62. @property (nonatomic, readonly) FBAccessTokenData *accessTokenData;
  63. /*!
  64. @abstract
  65. Returns an FBAppCall instance from a url, if applicable. Otherwise, returns nil.
  66. @param url The url.
  67. @return an FBAppCall instance if the url is valid; nil otherwise.
  68. @discussion This is typically used for App Link URLs.
  69. */
  70. + (FBAppCall *)appCallFromURL:(NSURL *)url;
  71. /*!
  72. @abstract
  73. Compares the receiving FBAppCall to the passed in FBAppCall
  74. @param appCall the other FBAppCall to compare to.
  75. @return YES if the AppCalls can be considered to be the same; NO if otherwise.
  76. */
  77. - (BOOL)isEqualToAppCall:(FBAppCall *)appCall;
  78. /*!
  79. @abstract
  80. Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method
  81. of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction
  82. with the native Facebook app or as part of SSO authorization flow.
  83. @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:].
  84. @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:].
  85. @return YES if the url was intended for the Facebook SDK, NO if not.
  86. */
  87. + (BOOL)handleOpenURL:(NSURL *)url
  88. sourceApplication:(NSString *)sourceApplication;
  89. /*!
  90. @abstract
  91. Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method
  92. of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction
  93. with the native Facebook app or as part of SSO authorization flow.
  94. @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:].
  95. @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:].
  96. @param handler Optional handler that gives the app the opportunity to do some further processing on urls
  97. that the SDK could not completely process. A fallback handler is not a requirement for such a url to be considered
  98. handled. The fallback handler, if specified, is only ever called sychronously, before the method returns.
  99. @return YES if the url was intended for the Facebook SDK, NO if not.
  100. */
  101. + (BOOL)handleOpenURL:(NSURL *)url
  102. sourceApplication:(NSString *)sourceApplication
  103. fallbackHandler:(FBAppCallHandler)handler;
  104. /*!
  105. @abstract
  106. Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method
  107. of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction
  108. with the native Facebook app or as part of SSO authorization flow.
  109. @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:].
  110. @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:].
  111. @param session If this url is being sent back to this app as part of SSO authorization flow, then pass in the
  112. session that was being opened. A nil value defaults to FBSession.activeSession
  113. @return YES if the url was intended for the Facebook SDK, NO if not.
  114. */
  115. + (BOOL)handleOpenURL:(NSURL *)url
  116. sourceApplication:(NSString *)sourceApplication
  117. withSession:(FBSession *)session;
  118. /*!
  119. @abstract
  120. Call this method from the [UIApplicationDelegate application:openURL:sourceApplication:annotation:] method
  121. of the AppDelegate for your app. It should be invoked for the proper processing of responses during interaction
  122. with the native Facebook app or as part of SSO authorization flow.
  123. @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:].
  124. @param sourceApplication The sourceApplication as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:].
  125. @param session If this url is being sent back to this app as part of SSO authorization flow, then pass in the
  126. session that was being opened. A nil value defaults to FBSession.activeSession
  127. @param handler Optional handler that gives the app the opportunity to do some further processing on urls
  128. that the SDK could not completely process. A fallback handler is not a requirement for such a url to be considered
  129. handled. The fallback handler, if specified, is only ever called sychronously, before the method returns.
  130. @return YES if the url was intended for the Facebook SDK, NO if not.
  131. */
  132. + (BOOL)handleOpenURL:(NSURL *)url
  133. sourceApplication:(NSString *)sourceApplication
  134. withSession:(FBSession *)session
  135. fallbackHandler:(FBAppCallHandler)handler;
  136. /*!
  137. @abstract
  138. Call this method when the application's applicationDidBecomeActive: is invoked.
  139. This ensures proper state management of any pending FBAppCalls or pending login flow for the
  140. FBSession.activeSession. If any pending FBAppCalls are found, their registered callbacks
  141. will be invoked with appropriate state
  142. */
  143. + (void)handleDidBecomeActive;
  144. /*!
  145. @abstract
  146. Call this method when the application's applicationDidBecomeActive: is invoked.
  147. This ensures proper state management of any pending FBAppCalls or a pending open for the
  148. passed in FBSession. If any pending FBAppCalls are found, their registered callbacks will
  149. be invoked with appropriate state
  150. @param session Session that is currently being used. Any pending calls to open will be cancelled.
  151. If no session is provided, then the activeSession (if present) is used.
  152. */
  153. + (void)handleDidBecomeActiveWithSession:(FBSession *)session;
  154. /*!
  155. @abstract
  156. Call this method from the main thread to fetch deferred applink data. This may require
  157. a network round trip. If successful, [+UIApplication openURL:] is invoked with the link
  158. data. Otherwise, the fallbackHandler will be dispatched to the main thread.
  159. @param fallbackHandler the handler to be invoked if applink data could not be opened.
  160. @discussion the fallbackHandler may contain an NSError instance to capture any errors. In the
  161. common case where there simply was no app link data, the NSError instance will be nil.
  162. This method should only be called from a location that occurs after any launching URL has
  163. been processed (e.g., you should call this method from your application delegate's applicationDidBecomeActive:)
  164. to avoid duplicate invocations of openURL:.
  165. If you must call this from the delegate's didFinishLaunchingWithOptions: you should
  166. only do so if the application is not being launched by a URL. For example,
  167. if (launchOptions[UIApplicationLaunchOptionsURLKey] == nil) {
  168. [FBAppCall openDeferredAppLink:^(NSError *error) {
  169. // ....
  170. }
  171. }
  172. */
  173. + (void)openDeferredAppLink:(FBAppLinkFallbackHandler)fallbackHandler;
  174. @end