commit | author | age
|
e0ec42
|
1 |
/* |
L |
2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* This source code is licensed under the license found in the |
|
6 |
* LICENSE file in the root directory of this source tree. |
|
7 |
*/ |
|
8 |
|
|
9 |
#if !TARGET_OS_TV |
|
10 |
|
|
11 |
#import <Foundation/Foundation.h> |
|
12 |
|
|
13 |
#import <FBSDKCoreKit/FBSDKConstants.h> |
|
14 |
|
|
15 |
NS_ASSUME_NONNULL_BEGIN |
|
16 |
|
|
17 |
@class FBSDKGraphErrorRecoveryProcessor; |
|
18 |
@protocol FBSDKGraphRequest; |
|
19 |
|
|
20 |
/// Defines a delegate for `FBSDKGraphErrorRecoveryProcessor`. |
|
21 |
NS_SWIFT_NAME(GraphErrorRecoveryProcessorDelegate) |
|
22 |
@protocol FBSDKGraphErrorRecoveryProcessorDelegate <NSObject> |
|
23 |
|
|
24 |
/** |
|
25 |
Indicates the error recovery has been attempted. |
|
26 |
@param processor the processor instance. |
|
27 |
@param didRecover YES if the recovery was successful. |
|
28 |
@param error the error that that was attempted to be recovered from. |
|
29 |
*/ |
|
30 |
- (void)processorDidAttemptRecovery:(FBSDKGraphErrorRecoveryProcessor *)processor |
|
31 |
didRecover:(BOOL)didRecover |
|
32 |
error:(nullable NSError *)error; |
|
33 |
|
|
34 |
@optional |
|
35 |
/** |
|
36 |
Indicates the processor is about to process the error. |
|
37 |
@param processor the processor instance. |
|
38 |
@param error the error is about to be processed. |
|
39 |
|
|
40 |
return NO if the processor should not process the error. For example, |
|
41 |
if you want to prevent alerts of localized messages but otherwise perform retries and recoveries, |
|
42 |
you could return NO for errors where userInfo[FBSDKGraphRequestErrorKey] equal to FBSDKGraphRequestErrorOther |
|
43 |
*/ |
|
44 |
- (BOOL)processorWillProcessError:(FBSDKGraphErrorRecoveryProcessor *)processor |
|
45 |
error:(nullable NSError *)error; |
|
46 |
|
|
47 |
@end |
|
48 |
|
|
49 |
/** |
|
50 |
Defines a type that can process Facebook NSErrors with best practices. |
|
51 |
|
|
52 |
Facebook NSErrors can contain FBSDKErrorRecoveryAttempting instances to recover from errors, or |
|
53 |
localized messages to present to the user. This class will process the instances as follows: |
|
54 |
|
|
55 |
1. If the error is temporary as indicated by FBSDKGraphRequestErrorKey, assume the recovery succeeded and |
|
56 |
notify the delegate. |
|
57 |
2. If a FBSDKErrorRecoveryAttempting instance is available, display an alert (dispatched to main thread) |
|
58 |
with the recovery options and call the instance's attemptRecoveryFromError method. |
|
59 |
3. If a FBSDKErrorRecoveryAttempting is not available, check the userInfo for FBSDKLocalizedErrorDescriptionKey |
|
60 |
and present that in an alert (dispatched to main thread). |
|
61 |
|
|
62 |
By default, FBSDKGraphRequests use this type to process errors and retry the request upon a successful |
|
63 |
recovery. |
|
64 |
|
|
65 |
Note that Facebook recovery attempters can present UI or even cause app switches (such as to login). Any such |
|
66 |
work is dispatched to the main thread (therefore your request handlers may then run on the main thread). |
|
67 |
|
|
68 |
Login recovery requires FBSDKLoginKit. Login will prompt the user |
|
69 |
for all permissions last granted. If any are declined on the new request, the recovery is not successful but |
|
70 |
the `[FBSDKAccessToken currentAccessToken]` might still have been updated. |
|
71 |
. |
|
72 |
*/ |
|
73 |
NS_SWIFT_NAME(GraphErrorRecoveryProcessor) |
|
74 |
@interface FBSDKGraphErrorRecoveryProcessor : NSObject |
|
75 |
|
|
76 |
/// Initializes a GraphErrorRecoveryProcessor with an access token string. |
|
77 |
- (instancetype)initWithAccessTokenString:(NSString *)accessTokenString; |
|
78 |
|
|
79 |
/** |
|
80 |
Attempts to process the error, return YES if the error can be processed. |
|
81 |
@param error the error to process. |
|
82 |
@param request the related request that may be reissued. |
|
83 |
@param delegate the delegate that will be retained until recovery is complete. |
|
84 |
*/ |
|
85 |
- (BOOL)processError:(NSError *)error |
|
86 |
request:(id<FBSDKGraphRequest>)request |
|
87 |
delegate:(nullable id<FBSDKGraphErrorRecoveryProcessorDelegate>)delegate; |
|
88 |
|
|
89 |
@end |
|
90 |
|
|
91 |
NS_ASSUME_NONNULL_END |
|
92 |
|
|
93 |
#endif |