commit | author | age
|
a0a843
|
1 |
// |
H |
2 |
// TWTRUserSessionVerifier.h |
|
3 |
// TwitterKit |
|
4 |
// |
|
5 |
// Created by Kang Chen on 1/23/15. |
|
6 |
// Copyright (c) 2015 Twitter. All rights reserved. |
|
7 |
// |
|
8 |
|
|
9 |
@class TWTRUserSessionVerifier; |
|
10 |
|
|
11 |
@protocol TWTRUserSessionVerifierDelegate <NSObject> |
|
12 |
|
|
13 |
- (void)userSessionVerifierNeedsSessionVerification:(TWTRUserSessionVerifier *)userSessionVerifier; |
|
14 |
|
|
15 |
@end |
|
16 |
|
|
17 |
FOUNDATION_EXPORT NSTimeInterval const TWTRUserSessionVerifierIntervalDaily; |
|
18 |
FOUNDATION_EXPORT NSTimeInterval const TWTRUserSessionVerifierDefaultDelay; |
|
19 |
|
|
20 |
/** |
|
21 |
* Manages verifying stored user sessions on a daily basis. This class depends on the Kit lifecycle |
|
22 |
* and `UIApplicationWillEnterForegroundNotification` event and checks whether the last verified |
|
23 |
* time has exceeded a day based on UTC date boundaries. Note that this does not mean we will aggressively |
|
24 |
* verify the second day of someone that started using the app at 11:59P and continues past 12:00A |
|
25 |
* due to 1) avoiding load spike to backend and 2) there is no good reliable way to randomize the |
|
26 |
* scheduling of the second verification due to constraints of iOS. Last verified time is only stored in memory |
|
27 |
* to minimize overhead on the host application. Verification is done on a best effort basis and we |
|
28 |
* will not retry if the network call fails for whatever reason. |
|
29 |
*/ |
|
30 |
@interface TWTRUserSessionVerifier : NSObject |
|
31 |
|
|
32 |
- (instancetype)init __unavailable; |
|
33 |
|
|
34 |
/** |
|
35 |
* Initializes a verifier for the current consumer application. |
|
36 |
* |
|
37 |
* @param delegate An object that will handle the verification of the session when necessary |
|
38 |
* @param maxDesiredInterval maximum desireable interval for how frequently a verify call should be made while |
|
39 |
* the host app is active. Calls might be made more frequently if the app is used |
|
40 |
* during the previous and current interval boundaries or we cannot not tell when |
|
41 |
* the last call was made. The latter will be de-dup on the backend. |
|
42 |
*/ |
|
43 |
- (instancetype)initWithDelegate:(id<TWTRUserSessionVerifierDelegate>)delegate maxDesiredInterval:(NSTimeInterval)maxDesiredInterval __attribute__((nonnull(1)))NS_DESIGNATED_INITIALIZER; |
|
44 |
|
|
45 |
/** |
|
46 |
* Makes a verify call immediately (delayed slightly to minimize app startup impact) and then |
|
47 |
* subscribes to `UIApplicationWillEnterForegroundNotification` to check for the next time we should |
|
48 |
* be making a verify call. |
|
49 |
* |
|
50 |
* @param delay The minimum time before which the message is sent. Specifying a delay of 0 does not |
|
51 |
* necessarily cause the selector to be performed immediately. The first verification is |
|
52 |
* still queued on the thread’s run loop and performed as soon as possible. |
|
53 |
*/ |
|
54 |
- (void)startVerificationAfterDelay:(NSTimeInterval)delay; |
|
55 |
|
|
56 |
@end |