FBSession.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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 <Accounts/Accounts.h>
  17. #import <Foundation/Foundation.h>
  18. #import "FBSDKMacros.h"
  19. // up-front decl's
  20. @class FBAccessTokenData;
  21. @class FBSession;
  22. @class FBSessionTokenCachingStrategy;
  23. #define FB_SESSIONSTATETERMINALBIT (1 << 8)
  24. #define FB_SESSIONSTATEOPENBIT (1 << 9)
  25. /*
  26. * Constants used by NSNotificationCenter for active session notification
  27. */
  28. /*! NSNotificationCenter name indicating that a new active session was set */
  29. FBSDK_EXTERN NSString *const FBSessionDidSetActiveSessionNotification;
  30. /*! NSNotificationCenter name indicating that an active session was unset */
  31. FBSDK_EXTERN NSString *const FBSessionDidUnsetActiveSessionNotification;
  32. /*! NSNotificationCenter name indicating that the active session is open */
  33. FBSDK_EXTERN NSString *const FBSessionDidBecomeOpenActiveSessionNotification;
  34. /*! NSNotificationCenter name indicating that there is no longer an open active session */
  35. FBSDK_EXTERN NSString *const FBSessionDidBecomeClosedActiveSessionNotification;
  36. /*!
  37. @typedef FBSessionState enum
  38. @abstract Passed to handler block each time a session state changes
  39. @discussion
  40. */
  41. typedef NS_ENUM(NSUInteger, FBSessionState) {
  42. /*! One of two initial states indicating that no valid cached token was found */
  43. FBSessionStateCreated = 0,
  44. /*! One of two initial session states indicating that a cached token was loaded;
  45. when a session is in this state, a call to open* will result in an open session,
  46. without UX or app-switching*/
  47. FBSessionStateCreatedTokenLoaded = 1,
  48. /*! One of three pre-open session states indicating that an attempt to open the session
  49. is underway*/
  50. FBSessionStateCreatedOpening = 2,
  51. /*! Open session state indicating user has logged in or a cached token is available */
  52. FBSessionStateOpen = 1 | FB_SESSIONSTATEOPENBIT,
  53. /*! Open session state indicating token has been extended, or the user has granted additional permissions */
  54. FBSessionStateOpenTokenExtended = 2 | FB_SESSIONSTATEOPENBIT,
  55. /*! Closed session state indicating that a login attempt failed */
  56. FBSessionStateClosedLoginFailed = 1 | FB_SESSIONSTATETERMINALBIT, // NSError obj w/more info
  57. /*! Closed session state indicating that the session was closed, but the users token
  58. remains cached on the device for later use */
  59. FBSessionStateClosed = 2 | FB_SESSIONSTATETERMINALBIT, // "
  60. };
  61. /*! helper macro to test for states that imply an open session */
  62. #define FB_ISSESSIONOPENWITHSTATE(state) (0 != (state & FB_SESSIONSTATEOPENBIT))
  63. /*! helper macro to test for states that are terminal */
  64. #define FB_ISSESSIONSTATETERMINAL(state) (0 != (state & FB_SESSIONSTATETERMINALBIT))
  65. /*!
  66. @typedef FBSessionLoginBehavior enum
  67. @abstract
  68. Passed to open to indicate whether Facebook Login should allow for fallback to be attempted.
  69. @discussion
  70. Facebook Login authorizes the application to act on behalf of the user, using the user's
  71. Facebook account. Usually a Facebook Login will rely on an account maintained outside of
  72. the application, by the native Facebook application, the browser, or perhaps the device
  73. itself. This avoids the need for a user to enter their username and password directly, and
  74. provides the most secure and lowest friction way for a user to authorize the application to
  75. interact with Facebook. If a Facebook Login is not possible, a fallback Facebook Login may be
  76. attempted, where the user is prompted to enter their credentials in a web-view hosted directly
  77. by the application.
  78. The `FBSessionLoginBehavior` enum specifies whether to allow fallback, disallow fallback, or
  79. force fallback login behavior. Most applications will use the default, which attempts a normal
  80. Facebook Login, and only falls back if needed. In rare cases, it may be preferable to disallow
  81. fallback Facebook Login completely, or to force a fallback login.
  82. */
  83. typedef NS_ENUM(NSUInteger, FBSessionLoginBehavior) {
  84. /*! Attempt Facebook Login, ask user for credentials if necessary */
  85. FBSessionLoginBehaviorWithFallbackToWebView = 0,
  86. /*! Attempt Facebook Login, no direct request for credentials will be made */
  87. FBSessionLoginBehaviorWithNoFallbackToWebView = 1,
  88. /*! Only attempt WebView Login; ask user for credentials */
  89. FBSessionLoginBehaviorForcingWebView = 2,
  90. /*! Attempt Facebook Login, prefering system account and falling back to fast app switch if necessary */
  91. FBSessionLoginBehaviorUseSystemAccountIfPresent = 3,
  92. /*! Attempt only to login with Safari */
  93. FBSessionLoginBehaviorForcingSafari = 4,
  94. };
  95. /*!
  96. @typedef FBSessionDefaultAudience enum
  97. @abstract
  98. Passed to open to indicate which default audience to use for sessions that post data to Facebook.
  99. @discussion
  100. Certain operations such as publishing a status or publishing a photo require an audience. When the user
  101. grants an application permission to perform a publish operation, a default audience is selected as the
  102. publication ceiling for the application. This enumerated value allows the application to select which
  103. audience to ask the user to grant publish permission for.
  104. */
  105. typedef NS_ENUM(NSUInteger, FBSessionDefaultAudience) {
  106. /*! No audience needed; this value is useful for cases where data will only be read from Facebook */
  107. FBSessionDefaultAudienceNone = 0,
  108. /*! Indicates that only the user is able to see posts made by the application */
  109. FBSessionDefaultAudienceOnlyMe = 10,
  110. /*! Indicates that the user's friends are able to see posts made by the application */
  111. FBSessionDefaultAudienceFriends = 20,
  112. /*! Indicates that all Facebook users are able to see posts made by the application */
  113. FBSessionDefaultAudienceEveryone = 30,
  114. };
  115. /*!
  116. @typedef FBSessionLoginType enum
  117. @abstract
  118. Used as the type of the loginType property in order to specify what underlying technology was used to
  119. login the user.
  120. @discussion
  121. The FBSession object is an abstraction over five distinct mechanisms. This enum allows an application
  122. to test for the mechanism used by a particular instance of FBSession. Usually the mechanism used for a
  123. given login does not matter, however for certain capabilities, the type of login can impact the behavior
  124. of other Facebook functionality.
  125. */
  126. typedef NS_ENUM(NSUInteger, FBSessionLoginType) {
  127. /*! A login type has not yet been established */
  128. FBSessionLoginTypeNone = 0,
  129. /*! A system integrated account was used to log the user into the application */
  130. FBSessionLoginTypeSystemAccount = 1,
  131. /*! The Facebook native application was used to log the user into the application */
  132. FBSessionLoginTypeFacebookApplication = 2,
  133. /*! Safari was used to log the user into the application */
  134. FBSessionLoginTypeFacebookViaSafari = 3,
  135. /*! A web view was used to log the user into the application */
  136. FBSessionLoginTypeWebView = 4,
  137. /*! A test user was used to create an open session */
  138. FBSessionLoginTypeTestUser = 5,
  139. };
  140. /*!
  141. @typedef
  142. @abstract Block type used to define blocks called by <FBSession> for state updates
  143. @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/
  144. for error handling best practices.
  145. Requesting additional permissions inside this handler (such as by calling
  146. `requestNewPublishPermissions`) should be avoided because it is a poor user
  147. experience and its behavior may vary depending on the login type. You should
  148. request the permissions closer to the operation that requires it (e.g., when
  149. the user performs some action).
  150. */
  151. typedef void (^FBSessionStateHandler)(FBSession *session,
  152. FBSessionState status,
  153. NSError *error);
  154. /*!
  155. @typedef
  156. @abstract Block type used to define blocks called by <[FBSession requestNewReadPermissions:completionHandler:]>
  157. and <[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:]>.
  158. @discussion See https://developers.facebook.com/docs/technical-guides/iossdk/errors/
  159. for error handling best practices.
  160. Requesting additional permissions inside this handler (such as by calling
  161. `requestNewPublishPermissions`) should be avoided because it is a poor user
  162. experience and its behavior may vary depending on the login type. You should
  163. request the permissions closer to the operation that requires it (e.g., when
  164. the user performs some action).
  165. */
  166. typedef void (^FBSessionRequestPermissionResultHandler)(FBSession *session,
  167. NSError *error);
  168. /*!
  169. @typedef
  170. @abstract Block type used to define blocks called by <[FBSession reauthorizeWithPermissions]>.
  171. @discussion You should use the preferred FBSessionRequestPermissionHandler typedef rather than
  172. this synonym, which has been deprecated.
  173. */
  174. typedef FBSessionRequestPermissionResultHandler FBSessionReauthorizeResultHandler __attribute__((deprecated));
  175. /*!
  176. @typedef
  177. @abstract Block type used to define blocks called for system credential renewals.
  178. @discussion
  179. */
  180. typedef void (^FBSessionRenewSystemCredentialsHandler)(ACAccountCredentialRenewResult result, NSError *error) ;
  181. /*!
  182. @class FBSession
  183. @abstract
  184. The `FBSession` object is used to authenticate a user and manage the user's session. After
  185. initializing a `FBSession` object the Facebook App ID and desired permissions are stored.
  186. Opening the session will initiate the authentication flow after which a valid user session
  187. should be available and subsequently cached. Closing the session can optionally clear the
  188. cache.
  189. If an <FBRequest> request requires user authorization then an `FBSession` object should be used.
  190. @discussion
  191. Instances of the `FBSession` class provide notification of state changes in the following ways:
  192. 1. Callers of certain `FBSession` methods may provide a block that will be called
  193. back in the course of state transitions for the session (e.g. login or session closed).
  194. 2. The object supports Key-Value Observing (KVO) for property changes.
  195. */
  196. @interface FBSession : NSObject
  197. /*!
  198. @methodgroup Creating a session
  199. */
  200. /*!
  201. @method
  202. @abstract
  203. Returns a newly initialized Facebook session with default values for the parameters
  204. to <initWithAppID:permissions:urlSchemeSuffix:tokenCacheStrategy:>.
  205. */
  206. - (instancetype)init;
  207. /*!
  208. @method
  209. @abstract
  210. Returns a newly initialized Facebook session with the specified permissions and other
  211. default values for parameters to <initWithAppID:permissions:urlSchemeSuffix:tokenCacheStrategy:>.
  212. @param permissions An array of strings representing the permissions to request during the
  213. authentication flow.
  214. @discussion
  215. It is required that any single permission request request (including initial log in) represent read-only permissions
  216. or publish permissions only; not both. The permissions passed here should reflect this requirement.
  217. */
  218. - (instancetype)initWithPermissions:(NSArray *)permissions;
  219. /*!
  220. @method
  221. @abstract
  222. Following are the descriptions of the arguments along with their
  223. defaults when ommitted.
  224. @param permissions An array of strings representing the permissions to request during the
  225. authentication flow.
  226. @param appID The Facebook App ID for the session. If nil is passed in the default App ID will be obtained from a call to <[FBSession defaultAppID]>. The default is nil.
  227. @param urlSchemeSuffix The URL Scheme Suffix to be used in scenarious where multiple iOS apps use one Facebook App ID. A value of nil indicates that this information should be pulled from [FBSettings defaultUrlSchemeSuffix]. The default is nil.
  228. @param tokenCachingStrategy Specifies a key name to use for cached token information in NSUserDefaults, nil
  229. indicates a default value of @"FBAccessTokenInformationKey".
  230. @discussion
  231. It is required that any single permission request request (including initial log in) represent read-only permissions
  232. or publish permissions only; not both. The permissions passed here should reflect this requirement.
  233. */
  234. - (instancetype)initWithAppID:(NSString *)appID
  235. permissions:(NSArray *)permissions
  236. urlSchemeSuffix:(NSString *)urlSchemeSuffix
  237. tokenCacheStrategy:(FBSessionTokenCachingStrategy *)tokenCachingStrategy;
  238. /*!
  239. @method
  240. @abstract
  241. Following are the descriptions of the arguments along with their
  242. defaults when ommitted.
  243. @param permissions An array of strings representing the permissions to request during the
  244. authentication flow.
  245. @param defaultAudience Most applications use FBSessionDefaultAudienceNone here, only specifying an audience when using reauthorize to request publish permissions.
  246. @param appID The Facebook App ID for the session. If nil is passed in the default App ID will be obtained from a call to <[FBSession defaultAppID]>. The default is nil.
  247. @param urlSchemeSuffix The URL Scheme Suffix to be used in scenarious where multiple iOS apps use one Facebook App ID. A value of nil indicates that this information should be pulled from [FBSettings defaultUrlSchemeSuffix]. The default is nil.
  248. @param tokenCachingStrategy Specifies a key name to use for cached token information in NSUserDefaults, nil
  249. indicates a default value of @"FBAccessTokenInformationKey".
  250. @discussion
  251. It is required that any single permission request request (including initial log in) represent read-only permissions
  252. or publish permissions only; not both. The permissions passed here should reflect this requirement. If publish permissions
  253. are used, then the audience must also be specified.
  254. */
  255. - (instancetype)initWithAppID:(NSString *)appID
  256. permissions:(NSArray *)permissions
  257. defaultAudience:(FBSessionDefaultAudience)defaultAudience
  258. urlSchemeSuffix:(NSString *)urlSchemeSuffix
  259. tokenCacheStrategy:(FBSessionTokenCachingStrategy *)tokenCachingStrategy;
  260. // instance readonly properties
  261. /*! @abstract Indicates whether the session is open and ready for use. */
  262. @property (readonly) BOOL isOpen;
  263. /*! @abstract Detailed session state */
  264. @property (readonly) FBSessionState state;
  265. /*! @abstract Identifies the Facebook app which the session object represents. */
  266. @property (readonly, copy) NSString *appID;
  267. /*! @abstract Identifies the URL Scheme Suffix used by the session. This is used when multiple iOS apps share a single Facebook app ID. */
  268. @property (readonly, copy) NSString *urlSchemeSuffix;
  269. /*! @abstract The access token for the session object.
  270. @discussion Deprecated. Use the `accessTokenData` property. */
  271. @property(readonly, copy) NSString *accessToken
  272. __attribute__((deprecated));
  273. /*! @abstract The expiration date of the access token for the session object.
  274. @discussion Deprecated. Use the `accessTokenData` property. */
  275. @property(readonly, copy) NSDate *expirationDate
  276. __attribute__((deprecated));
  277. /*! @abstract The permissions granted to the access token during the authentication flow. */
  278. @property (readonly, copy) NSArray *permissions;
  279. /*! @abstract Specifies the login type used to authenticate the user.
  280. @discussion Deprecated. Use the `accessTokenData` property. */
  281. @property(readonly) FBSessionLoginType loginType
  282. __attribute__((deprecated));
  283. /*! @abstract Gets the FBAccessTokenData for the session */
  284. @property (readonly, copy) FBAccessTokenData *accessTokenData;
  285. /*!
  286. @abstract
  287. Returns a collection of permissions that have been declined by the user for this
  288. given session instance.
  289. @discussion
  290. A "declined" permission is one that had been requested but was either skipped or removed by
  291. the user during the login flow. Note that once the permission has been granted (either by
  292. requesting again or detected by a permissions refresh), it will be removed from this collection.
  293. */
  294. @property (readonly, copy) NSArray *declinedPermissions;
  295. /*!
  296. @methodgroup Instance methods
  297. */
  298. /*!
  299. @method
  300. @abstract Opens a session for the Facebook.
  301. @discussion
  302. A session may not be used with <FBRequest> and other classes in the SDK until it is open. If, prior
  303. to calling open, the session is in the <FBSessionStateCreatedTokenLoaded> state, then no UX occurs, and
  304. the session becomes available for use. If the session is in the <FBSessionStateCreated> state, prior
  305. to calling open, then a call to open causes login UX to occur, either via the Facebook application
  306. or via mobile Safari.
  307. Open may be called at most once and must be called after the `FBSession` is initialized. Open must
  308. be called before the session is closed. Calling an open method at an invalid time will result in
  309. an exception. The open session methods may be passed a block that will be called back when the session
  310. state changes. The block will be released when the session is closed.
  311. @param handler A block to call with the state changes. The default is nil.
  312. */
  313. - (void)openWithCompletionHandler:(FBSessionStateHandler)handler;
  314. /*!
  315. @method
  316. @abstract Logs a user on to Facebook.
  317. @discussion
  318. A session may not be used with <FBRequest> and other classes in the SDK until it is open. If, prior
  319. to calling open, the session is in the <FBSessionStateCreatedTokenLoaded> state, then no UX occurs, and
  320. the session becomes available for use. If the session is in the <FBSessionStateCreated> state, prior
  321. to calling open, then a call to open causes login UX to occur, either via the Facebook application
  322. or via mobile Safari.
  323. The method may be called at most once and must be called after the `FBSession` is initialized. It must
  324. be called before the session is closed. Calling the method at an invalid time will result in
  325. an exception. The open session methods may be passed a block that will be called back when the session
  326. state changes. The block will be released when the session is closed.
  327. @param behavior Controls whether to allow, force, or prohibit Facebook Login or Inline Facebook Login. The default
  328. is to allow Facebook Login, with fallback to Inline Facebook Login.
  329. @param handler A block to call with session state changes. The default is nil.
  330. */
  331. - (void)openWithBehavior:(FBSessionLoginBehavior)behavior
  332. completionHandler:(FBSessionStateHandler)handler;
  333. /*!
  334. @method
  335. @abstract Imports an existing access token and opens the session with it.
  336. @discussion
  337. The method attempts to open the session using an existing access token. No UX will occur. If
  338. successful, the session with be in an Open state and the method will return YES; otherwise, NO.
  339. The method may be called at most once and must be called after the `FBSession` is initialized (see below).
  340. It must be called before the session is closed. Calling the method at an invalid time will result in
  341. an exception. The open session methods may be passed a block that will be called back when the session
  342. state changes. The block will be released when the session is closed.
  343. The initialized session must not have already been initialized from a cache (for example, you could use
  344. the `[FBSessionTokenCachingStrategy nullCacheInstance]` instance).
  345. @param accessTokenData The token data. See `FBAccessTokenData` for construction methods.
  346. @param handler A block to call with session state changes. The default is nil.
  347. */
  348. - (BOOL)openFromAccessTokenData:(FBAccessTokenData *)accessTokenData completionHandler:(FBSessionStateHandler) handler;
  349. /*!
  350. @abstract
  351. Closes the local in-memory session object, but does not clear the persisted token cache.
  352. */
  353. - (void)close;
  354. /*!
  355. @abstract
  356. Closes the in-memory session, and clears any persisted cache related to the session.
  357. */
  358. - (void)closeAndClearTokenInformation;
  359. /*!
  360. @abstract
  361. Reauthorizes the session, with additional permissions.
  362. @param permissions An array of strings representing the permissions to request during the
  363. authentication flow. A value of nil indicates basic permissions. The default is nil.
  364. @param behavior Controls whether to allow, force, or prohibit Facebook Login. The default
  365. is to allow Facebook Login and fall back to Inline Facebook Login if needed.
  366. @param handler A block to call with session state changes. The default is nil.
  367. @discussion Methods and properties that specify permissions without a read or publish
  368. qualification are deprecated; use of a read-qualified or publish-qualified alternative is preferred
  369. (e.g. reauthorizeWithReadPermissions or reauthorizeWithPublishPermissions)
  370. */
  371. - (void)reauthorizeWithPermissions:(NSArray *)permissions
  372. behavior:(FBSessionLoginBehavior)behavior
  373. completionHandler:(FBSessionReauthorizeResultHandler)handler
  374. __attribute__((deprecated));
  375. /*!
  376. @abstract
  377. Reauthorizes the session, with additional permissions.
  378. @param readPermissions An array of strings representing the permissions to request during the
  379. authentication flow. A value of nil indicates basic permissions.
  380. @param handler A block to call with session state changes. The default is nil.
  381. @discussion This method is a deprecated alias of <[FBSession requestNewReadPermissions:completionHandler:]>. Consider
  382. using <[FBSession requestNewReadPermissions:completionHandler:]>, which is preferred for readability.
  383. */
  384. - (void)reauthorizeWithReadPermissions:(NSArray *)readPermissions
  385. completionHandler:(FBSessionReauthorizeResultHandler)handler
  386. __attribute__((deprecated));
  387. /*!
  388. @abstract
  389. Reauthorizes the session, with additional permissions.
  390. @param writePermissions An array of strings representing the permissions to request during the
  391. authentication flow.
  392. @param defaultAudience Specifies the audience for posts.
  393. @param handler A block to call with session state changes. The default is nil.
  394. @discussion This method is a deprecated alias of <[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:]>.
  395. Consider using <[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:]>, which is preferred for readability.
  396. */
  397. - (void)reauthorizeWithPublishPermissions:(NSArray *)writePermissions
  398. defaultAudience:(FBSessionDefaultAudience)defaultAudience
  399. completionHandler:(FBSessionReauthorizeResultHandler)handler
  400. __attribute__((deprecated));
  401. /*!
  402. @abstract
  403. Requests new or additional read permissions for the session.
  404. @param readPermissions An array of strings representing the permissions to request during the
  405. authentication flow. A value of nil indicates basic permissions.
  406. @param handler A block to call with session state changes. The default is nil.
  407. @discussion The handler, if non-nil, is called once the operation has completed or failed. This is in contrast to the
  408. state completion handler used in <[FBSession openWithCompletionHandler:]> (and other `open*` methods) which is called
  409. for each state-change for the session.
  410. */
  411. - (void)requestNewReadPermissions:(NSArray *)readPermissions
  412. completionHandler:(FBSessionRequestPermissionResultHandler)handler;
  413. /*!
  414. @abstract
  415. Requests new or additional write permissions for the session.
  416. @param writePermissions An array of strings representing the permissions to request during the
  417. authentication flow.
  418. @param defaultAudience Specifies the audience for posts.
  419. @param handler A block to call with session state changes. The default is nil.
  420. @discussion The handler, if non-nil, is called once the operation has completed or failed. This is in contrast to the
  421. state completion handler used in <[FBSession openWithCompletionHandler:]> (and other `open*` methods) which is called
  422. for each state-change for the session.
  423. */
  424. - (void)requestNewPublishPermissions:(NSArray *)writePermissions
  425. defaultAudience:(FBSessionDefaultAudience)defaultAudience
  426. completionHandler:(FBSessionRequestPermissionResultHandler)handler;
  427. /*!
  428. @abstract Refreshes the current permissions for the session.
  429. @param handler Called after completion of the refresh.
  430. @discussion This will update the sessions' permissions array from the server. This can be
  431. useful if you want to make sure the local permissions are up to date.
  432. */
  433. - (void)refreshPermissionsWithCompletionHandler:(FBSessionRequestPermissionResultHandler)handler;
  434. /*!
  435. @abstract
  436. A helper method that is used to provide an implementation for
  437. [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. It should be invoked during
  438. the Facebook Login flow and will update the session information based on the incoming URL.
  439. @param url The URL as passed to [UIApplicationDelegate application:openURL:sourceApplication:annotation:].
  440. */
  441. - (BOOL)handleOpenURL:(NSURL *)url;
  442. /*!
  443. @abstract
  444. A helper method that is used to provide an implementation for
  445. [UIApplicationDelegate applicationDidBecomeActive:] to properly resolve session state for
  446. the Facebook Login flow, specifically to support app-switch login.
  447. */
  448. - (void)handleDidBecomeActive;
  449. /*!
  450. @abstract
  451. Assign the block to be invoked for session state changes.
  452. @param stateChangeHandler the handler block.
  453. @discussion
  454. This will overwrite any state change handler that was already assigned. Typically,
  455. you should only use this setter if you were unable to assign a state change handler explicitly.
  456. One example of this is if you are not opening the session (e.g., using the `open*`)
  457. but still want to assign a `FBSessionStateHandler` block. This can happen when the SDK
  458. opens a session from an app link.
  459. */
  460. - (void)setStateChangeHandler:(FBSessionStateHandler)stateChangeHandler;
  461. /*!
  462. @abstract
  463. Returns true if the specified permission has been granted to this session.
  464. @param permission the permission to verify.
  465. @discussion
  466. This is a convenience helper for checking if `pemission` is inside the permissions array.
  467. */
  468. - (BOOL)hasGranted:(NSString *)permission;
  469. /*!
  470. @methodgroup Class methods
  471. */
  472. /*!
  473. @abstract
  474. This is the simplest method for opening a session with Facebook. Using sessionOpen logs on a user,
  475. and sets the static activeSession which becomes the default session object for any Facebook UI widgets
  476. used by the application. This session becomes the active session, whether open succeeds or fails.
  477. Note, if there is not a cached token available, this method will present UI to the user in order to
  478. open the session via explicit login by the user.
  479. @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if
  480. no login UI will be required to accomplish the operation. For example, at application startup it may not
  481. be disirable to transition to login UI for the user, and yet an open session is desired so long as a cached
  482. token can be used to open the session. Passing NO to this argument, assures the method will not present UI
  483. to the user in order to open the session.
  484. @discussion
  485. Returns YES if the session was opened synchronously without presenting UI to the user. This occurs
  486. when there is a cached token available from a previous run of the application. If NO is returned, this indicates
  487. that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is
  488. possible that the user will login, and the session will become open asynchronously. The primary use for
  489. this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session
  490. is opened via cache.
  491. */
  492. + (BOOL)openActiveSessionWithAllowLoginUI:(BOOL)allowLoginUI;
  493. /*!
  494. @abstract
  495. This is a simple method for opening a session with Facebook. Using sessionOpen logs on a user,
  496. and sets the static activeSession which becomes the default session object for any Facebook UI widgets
  497. used by the application. This session becomes the active session, whether open succeeds or fails.
  498. @param permissions An array of strings representing the permissions to request during the
  499. authentication flow. A value of nil indicates basic permissions. A nil value specifies
  500. default permissions.
  501. @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if
  502. no login UI will be required to accomplish the operation. For example, at application startup it may not
  503. be desirable to transition to login UI for the user, and yet an open session is desired so long as a cached
  504. token can be used to open the session. Passing NO to this argument, assures the method will not present UI
  505. to the user in order to open the session.
  506. @param handler Many applications will benefit from notification when a session becomes invalid
  507. or undergoes other state transitions. If a block is provided, the FBSession
  508. object will call the block each time the session changes state.
  509. @discussion
  510. Returns true if the session was opened synchronously without presenting UI to the user. This occurs
  511. when there is a cached token available from a previous run of the application. If NO is returned, this indicates
  512. that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is
  513. possible that the user will login, and the session will become open asynchronously. The primary use for
  514. this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session
  515. is opened via cache.
  516. It is required that initial permissions requests represent read-only permissions only. If publish
  517. permissions are needed, you may use reauthorizeWithPermissions to specify additional permissions as
  518. well as an audience. Use of this method will result in a legacy fast-app-switch Facebook Login due to
  519. the requirement to separate read and publish permissions for newer applications. Methods and properties
  520. that specify permissions without a read or publish qualification are deprecated; use of a read-qualified
  521. or publish-qualified alternative is preferred.
  522. */
  523. + (BOOL)openActiveSessionWithPermissions:(NSArray *)permissions
  524. allowLoginUI:(BOOL)allowLoginUI
  525. completionHandler:(FBSessionStateHandler)handler
  526. __attribute__((deprecated));
  527. /*!
  528. @abstract
  529. This is a simple method for opening a session with Facebook. Using sessionOpen logs on a user,
  530. and sets the static activeSession which becomes the default session object for any Facebook UI widgets
  531. used by the application. This session becomes the active session, whether open succeeds or fails.
  532. @param readPermissions An array of strings representing the read permissions to request during the
  533. authentication flow. It is not allowed to pass publish permissions to this method.
  534. @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if
  535. no login UI will be required to accomplish the operation. For example, at application startup it may not
  536. be desirable to transition to login UI for the user, and yet an open session is desired so long as a cached
  537. token can be used to open the session. Passing NO to this argument, assures the method will not present UI
  538. to the user in order to open the session.
  539. @param handler Many applications will benefit from notification when a session becomes invalid
  540. or undergoes other state transitions. If a block is provided, the FBSession
  541. object will call the block each time the session changes state.
  542. @discussion
  543. Returns true if the session was opened synchronously without presenting UI to the user. This occurs
  544. when there is a cached token available from a previous run of the application. If NO is returned, this indicates
  545. that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is
  546. possible that the user will login, and the session will become open asynchronously. The primary use for
  547. this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session
  548. is opened via cache.
  549. */
  550. + (BOOL)openActiveSessionWithReadPermissions:(NSArray *)readPermissions
  551. allowLoginUI:(BOOL)allowLoginUI
  552. completionHandler:(FBSessionStateHandler)handler;
  553. /*!
  554. @abstract
  555. This is a simple method for opening a session with Facebook. Using sessionOpen logs on a user,
  556. and sets the static activeSession which becomes the default session object for any Facebook UI widgets
  557. used by the application. This session becomes the active session, whether open succeeds or fails.
  558. @param publishPermissions An array of strings representing the publish permissions to request during the
  559. authentication flow.
  560. @param defaultAudience Anytime an app publishes on behalf of a user, the post must have an audience (e.g. me, my friends, etc.)
  561. The default audience is used to notify the user of the cieling that the user agrees to grant to the app for the provided permissions.
  562. @param allowLoginUI Sometimes it is useful to attempt to open a session, but only if
  563. no login UI will be required to accomplish the operation. For example, at application startup it may not
  564. be desirable to transition to login UI for the user, and yet an open session is desired so long as a cached
  565. token can be used to open the session. Passing NO to this argument, assures the method will not present UI
  566. to the user in order to open the session.
  567. @param handler Many applications will benefit from notification when a session becomes invalid
  568. or undergoes other state transitions. If a block is provided, the FBSession
  569. object will call the block each time the session changes state.
  570. @discussion
  571. Returns true if the session was opened synchronously without presenting UI to the user. This occurs
  572. when there is a cached token available from a previous run of the application. If NO is returned, this indicates
  573. that the session was not immediately opened, via cache. However, if YES was passed as allowLoginUI, then it is
  574. possible that the user will login, and the session will become open asynchronously. The primary use for
  575. this return value is to switch-on facebook capabilities in your UX upon startup, in the case where the session
  576. is opened via cache.
  577. */
  578. + (BOOL)openActiveSessionWithPublishPermissions:(NSArray *)publishPermissions
  579. defaultAudience:(FBSessionDefaultAudience)defaultAudience
  580. allowLoginUI:(BOOL)allowLoginUI
  581. completionHandler:(FBSessionStateHandler)handler;
  582. /*!
  583. @abstract
  584. An application may get or set the current active session. Certain high-level components in the SDK
  585. will use the activeSession to set default session (e.g. `FBLoginView`, `FBFriendPickerViewController`)
  586. @discussion
  587. If sessionOpen* is called, the resulting `FBSession` object also becomes the activeSession. If another
  588. session was active at the time, it is closed automatically. If activeSession is called when no session
  589. is active, a session object is instatiated and returned; in this case open must be called on the session
  590. in order for it to be useable for communication with Facebook.
  591. */
  592. + (FBSession *)activeSession;
  593. /*!
  594. @abstract
  595. An application may get or set the current active session. Certain high-level components in the SDK
  596. will use the activeSession to set default session (e.g. `FBLoginView`, `FBFriendPickerViewController`)
  597. @param session The FBSession object to become the active session
  598. @discussion
  599. If an application prefers the flexibilility of directly instantiating a session object, an active
  600. session can be set directly.
  601. */
  602. + (FBSession *)setActiveSession:(FBSession *)session;
  603. /*!
  604. @method
  605. @abstract Set the default Facebook App ID to use for sessions. The app ID may be
  606. overridden on a per session basis.
  607. @discussion This method has been deprecated in favor of [FBSettings setDefaultAppID].
  608. @param appID The default Facebook App ID to use for <FBSession> methods.
  609. */
  610. + (void)setDefaultAppID:(NSString *)appID __attribute__((deprecated));
  611. /*!
  612. @method
  613. @abstract Get the default Facebook App ID to use for sessions. If not explicitly
  614. set, the default will be read from the application's plist. The app ID may be
  615. overridden on a per session basis.
  616. @discussion This method has been deprecated in favor of [FBSettings defaultAppID].
  617. */
  618. + (NSString *)defaultAppID __attribute__((deprecated));
  619. /*!
  620. @method
  621. @abstract Set the default url scheme suffix to use for sessions. The url
  622. scheme suffix may be overridden on a per session basis.
  623. @discussion This method has been deprecated in favor of [FBSettings setDefaultUrlSchemeSuffix].
  624. @param urlSchemeSuffix The default url scheme suffix to use for <FBSession> methods.
  625. */
  626. + (void)setDefaultUrlSchemeSuffix:(NSString *)urlSchemeSuffix __attribute__((deprecated));
  627. /*!
  628. @method
  629. @abstract Get the default url scheme suffix used for sessions. If not
  630. explicitly set, the default will be read from the application's plist. The
  631. url scheme suffix may be overridden on a per session basis.
  632. @discussion This method has been deprecated in favor of [FBSettings defaultUrlSchemeSuffix].
  633. */
  634. + (NSString *)defaultUrlSchemeSuffix __attribute__((deprecated));
  635. /*!
  636. @method
  637. @abstract Issues an asychronous renewCredentialsForAccount call to the device Facebook account store.
  638. @param handler The completion handler to call when the renewal is completed. The handler will be
  639. invoked on the main thread.
  640. @discussion This can be used to explicitly renew account credentials on iOS 6 devices and is provided
  641. as a convenience wrapper around `[ACAccountStore renewCredentialsForAccount:completion]`. Note the
  642. method will not issue the renewal call if the the Facebook account has not been set on the device, or
  643. if access had not been granted to the account (though the handler wil receive an error).
  644. This is safe to call (and will surface an error to the handler) on versions of iOS before 6 or if the user
  645. logged in via Safari or Facebook SSO.
  646. */
  647. + (void)renewSystemCredentials:(FBSessionRenewSystemCredentialsHandler)handler;
  648. @end