FBSDKGraphErrorRecoveryProcessor.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  2. //
  3. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  4. // copy, modify, and distribute this software in source code or binary form for use
  5. // in connection with the web services and APIs provided by Facebook.
  6. //
  7. // As with any software that integrates with the Facebook platform, your use of
  8. // this software is subject to the Facebook Developer Principles and Policies
  9. // [http://developers.facebook.com/policy/]. This copyright notice shall be
  10. // included in all copies or substantial portions of the software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. #import <Foundation/Foundation.h>
  19. #import "FBSDKConstants.h"
  20. @class FBSDKGraphErrorRecoveryProcessor;
  21. @class FBSDKGraphRequest;
  22. /**
  23. Defines a delegate for `FBSDKGraphErrorRecoveryProcessor`.
  24. */
  25. @protocol FBSDKGraphErrorRecoveryProcessorDelegate<NSObject>
  26. /**
  27. Indicates the error recovery has been attempted.
  28. @param processor the processor instance.
  29. @param didRecover YES if the recovery was successful.
  30. @param error the error that that was attempted to be recovered from.
  31. */
  32. - (void)processorDidAttemptRecovery:(FBSDKGraphErrorRecoveryProcessor *)processor didRecover:(BOOL)didRecover error:(NSError *)error;
  33. @optional
  34. /**
  35. Indicates the processor is about to process the error.
  36. @param processor the processor instance.
  37. @param error the error is about to be processed.
  38. return NO if the processor should not process the error. For example,
  39. if you want to prevent alerts of localized messages but otherwise perform retries and recoveries,
  40. you could return NO for errors where userInfo[FBSDKGraphRequestErrorKey] equal to FBSDKGraphRequestErrorOther
  41. */
  42. - (BOOL)processorWillProcessError:(FBSDKGraphErrorRecoveryProcessor *)processor error:(NSError *)error;
  43. @end
  44. /**
  45. Defines a type that can process Facebook NSErrors with best practices.
  46. Facebook NSErrors can contain FBSDKErrorRecoveryAttempting instances to recover from errors, or
  47. localized messages to present to the user. This class will process the instances as follows:
  48. 1. If the error is temporary as indicated by FBSDKGraphRequestErrorKey, assume the recovery succeeded and
  49. notify the delegate.
  50. 2. If a FBSDKErrorRecoveryAttempting instance is available, display an alert (dispatched to main thread)
  51. with the recovery options and call the instance's [ attemptRecoveryFromError:optionIndex:...].
  52. 3. If a FBSDKErrorRecoveryAttempting is not available, check the userInfo for FBSDKLocalizedErrorDescriptionKey
  53. and present that in an alert (dispatched to main thread).
  54. By default, FBSDKGraphRequests use this type to process errors and retry the request upon a successful
  55. recovery.
  56. Note that Facebook recovery attempters can present UI or even cause app switches (such as to login). Any such
  57. work is dispatched to the main thread (therefore your request handlers may then run on the main thread).
  58. Login recovery requires FBSDKLoginKit. Login will use FBSDKLoginBehaviorNative and will prompt the user
  59. for all permissions last granted. If any are declined on the new request, the recovery is not successful but
  60. the `[FBSDKAccessToken currentAccessToken]` might still have been updated.
  61. .
  62. */
  63. @interface FBSDKGraphErrorRecoveryProcessor : NSObject
  64. /**
  65. Gets the delegate. Note this is a strong reference, and is nil'ed out after recovery is complete.
  66. */
  67. @property (nonatomic, strong, readonly) id<FBSDKGraphErrorRecoveryProcessorDelegate>delegate;
  68. /**
  69. Attempts to process the error, return YES if the error can be processed.
  70. @param error the error to process.
  71. @param request the related request that may be reissued.
  72. @param delegate the delegate that will be retained until recovery is complete.
  73. */
  74. - (BOOL)processError:(NSError *)error request:(FBSDKGraphRequest *)request delegate:(id<FBSDKGraphErrorRecoveryProcessorDelegate>) delegate;
  75. /**
  76. The callback for FBSDKErrorRecoveryAttempting
  77. @param didRecover if the recovery succeeded
  78. @param contextInfo unused
  79. */
  80. - (void)didPresentErrorWithRecovery:(BOOL)didRecover contextInfo:(void *)contextInfo;
  81. @end