commit | author | age
|
2e29a3
|
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 |
/** |
|
21 |
Defines a delegate for `FBSDKGraphErrorRecoveryProcessor`. |
|
22 |
*/ |
|
23 |
NS_SWIFT_NAME(GraphErrorRecoveryProcessorDelegate) |
|
24 |
@protocol FBSDKGraphErrorRecoveryProcessorDelegate <NSObject> |
|
25 |
|
|
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 |
|
33 |
didRecover:(BOOL)didRecover |
|
34 |
error:(nullable NSError *)error; |
|
35 |
|
|
36 |
@optional |
|
37 |
/** |
|
38 |
Indicates the processor is about to process the error. |
|
39 |
@param processor the processor instance. |
|
40 |
@param error the error is about to be processed. |
|
41 |
|
|
42 |
return NO if the processor should not process the error. For example, |
|
43 |
if you want to prevent alerts of localized messages but otherwise perform retries and recoveries, |
|
44 |
you could return NO for errors where userInfo[FBSDKGraphRequestErrorKey] equal to FBSDKGraphRequestErrorOther |
|
45 |
*/ |
|
46 |
- (BOOL)processorWillProcessError:(FBSDKGraphErrorRecoveryProcessor *)processor |
|
47 |
error:(nullable NSError *)error; |
|
48 |
|
|
49 |
@end |
|
50 |
|
|
51 |
NS_ASSUME_NONNULL_END |
|
52 |
|
|
53 |
NS_ASSUME_NONNULL_BEGIN |
|
54 |
|
|
55 |
/** |
|
56 |
Defines a type that can process Facebook NSErrors with best practices. |
|
57 |
|
|
58 |
Facebook NSErrors can contain FBSDKErrorRecoveryAttempting instances to recover from errors, or |
|
59 |
localized messages to present to the user. This class will process the instances as follows: |
|
60 |
|
|
61 |
1. If the error is temporary as indicated by FBSDKGraphRequestErrorKey, assume the recovery succeeded and |
|
62 |
notify the delegate. |
|
63 |
2. If a FBSDKErrorRecoveryAttempting instance is available, display an alert (dispatched to main thread) |
|
64 |
with the recovery options and call the instance's attemptRecoveryFromError method. |
|
65 |
3. If a FBSDKErrorRecoveryAttempting is not available, check the userInfo for FBSDKLocalizedErrorDescriptionKey |
|
66 |
and present that in an alert (dispatched to main thread). |
|
67 |
|
|
68 |
By default, FBSDKGraphRequests use this type to process errors and retry the request upon a successful |
|
69 |
recovery. |
|
70 |
|
|
71 |
Note that Facebook recovery attempters can present UI or even cause app switches (such as to login). Any such |
|
72 |
work is dispatched to the main thread (therefore your request handlers may then run on the main thread). |
|
73 |
|
|
74 |
Login recovery requires FBSDKLoginKit. Login will prompt the user |
|
75 |
for all permissions last granted. If any are declined on the new request, the recovery is not successful but |
|
76 |
the `[FBSDKAccessToken currentAccessToken]` might still have been updated. |
|
77 |
. |
|
78 |
*/ |
|
79 |
NS_SWIFT_NAME(GraphErrorRecoveryProcessor) |
|
80 |
@interface FBSDKGraphErrorRecoveryProcessor : NSObject |
|
81 |
|
|
82 |
/** |
|
83 |
Initializes a GraphErrorRecoveryProcessor with an access token string. |
|
84 |
*/ |
|
85 |
- (instancetype)initWithAccessTokenString:(NSString *)accessTokenString; |
|
86 |
|
|
87 |
/** |
|
88 |
Attempts to process the error, return YES if the error can be processed. |
|
89 |
@param error the error to process. |
|
90 |
@param request the related request that may be reissued. |
|
91 |
@param delegate the delegate that will be retained until recovery is complete. |
|
92 |
*/ |
|
93 |
- (BOOL)processError:(NSError *)error |
|
94 |
request:(id<FBSDKGraphRequest>)request |
|
95 |
delegate:(nullable id<FBSDKGraphErrorRecoveryProcessorDelegate>)delegate; |
|
96 |
|
|
97 |
@end |
|
98 |
|
|
99 |
NS_ASSUME_NONNULL_END |
|
100 |
|
|
101 |
#endif |