1 |
efrain |
1 |
/*
|
|
|
2 |
* Copyright 2017 Google
|
|
|
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 |
#import <Foundation/Foundation.h>
|
|
|
18 |
|
|
|
19 |
NS_ASSUME_NONNULL_BEGIN
|
|
|
20 |
@interface FIRIAMImpressionRecord : NSObject
|
|
|
21 |
@property(nonatomic, readonly, copy) NSString *messageID;
|
|
|
22 |
@property(nonatomic, readonly) long impressionTimeInSeconds;
|
|
|
23 |
|
|
|
24 |
- (NSString *)description;
|
|
|
25 |
|
|
|
26 |
- (instancetype)init NS_UNAVAILABLE;
|
|
|
27 |
- (instancetype)initWithMessageID:(NSString *)messageID
|
|
|
28 |
impressionTimeInSeconds:(long)impressionTime NS_DESIGNATED_INITIALIZER;
|
|
|
29 |
@end
|
|
|
30 |
|
|
|
31 |
// this protocol defines the interface for classes that can be used to track info regarding
|
|
|
32 |
// display & fetch of iam messages. The info tracked here can be used to decide if it's due for
|
|
|
33 |
// next display and/or fetch of iam messages.
|
|
|
34 |
@protocol FIRIAMBookKeeper
|
|
|
35 |
@property(nonatomic, readonly) double lastDisplayTime;
|
|
|
36 |
@property(nonatomic, readonly) double lastFetchTime;
|
|
|
37 |
@property(nonatomic, readonly) NSTimeInterval nextFetchWaitTime;
|
|
|
38 |
|
|
|
39 |
// only call this when it's considered to be a valid impression (for example, meeting the minimum
|
|
|
40 |
// display time requirement).
|
|
|
41 |
- (void)recordNewImpressionForMessage:(NSString *)messageID
|
|
|
42 |
withStartTimestampInSeconds:(double)timestamp;
|
|
|
43 |
|
|
|
44 |
- (void)recordNewFetchWithFetchCount:(NSInteger)fetchedMsgCount
|
|
|
45 |
withTimestampInSeconds:(double)fetchTimestamp
|
|
|
46 |
nextFetchWaitTime:(nullable NSNumber *)nextFetchWaitTime;
|
|
|
47 |
|
|
|
48 |
// When we fetch the eligible message list from the sdk server, it can contain messages that are
|
|
|
49 |
// already impressed for those that are defined to be displayed repeatedly (messages with custom
|
|
|
50 |
// display frequency). We need then clean up the impression records for these messages so that
|
|
|
51 |
// they can be displayed again on client side.
|
|
|
52 |
- (void)clearImpressionsWithMessageList:(NSArray<NSString *> *)messageList;
|
|
|
53 |
// fetch the impression list
|
|
|
54 |
- (NSArray<FIRIAMImpressionRecord *> *)getImpressions;
|
|
|
55 |
|
|
|
56 |
// For certain clients, they only need to get the list of the message ids in existing impression
|
|
|
57 |
// records. This is a helper method for that.
|
|
|
58 |
- (NSArray<NSString *> *)getMessageIDsFromImpressions;
|
|
|
59 |
@end
|
|
|
60 |
|
|
|
61 |
// implementation of FIRIAMBookKeeper protocol by storing data within iOS UserDefaults.
|
|
|
62 |
// TODO: switch to something else if there is risks for the data being unintentionally deleted by
|
|
|
63 |
// the app
|
|
|
64 |
@interface FIRIAMBookKeeperViaUserDefaults : NSObject <FIRIAMBookKeeper>
|
|
|
65 |
|
|
|
66 |
- (instancetype)init NS_UNAVAILABLE;
|
|
|
67 |
- (instancetype)initWithUserDefaults:(NSUserDefaults *)userDefaults NS_DESIGNATED_INITIALIZER;
|
|
|
68 |
|
|
|
69 |
// for testing, don't use them for production purpose
|
|
|
70 |
- (void)cleanupImpressions;
|
|
|
71 |
- (void)cleanupFetchRecords;
|
|
|
72 |
|
|
|
73 |
@end
|
|
|
74 |
|
|
|
75 |
NS_ASSUME_NONNULL_END
|