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