Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/*
2
 * Copyright 2019 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
#import "FirebaseRemoteConfig/Sources/RCNConfigContent.h"
20
 
21
typedef NS_ENUM(NSInteger, RCNUpdateOption) {
22
  RCNUpdateOptionApplyTime,
23
  RCNUpdateOptionDefaultTime,
24
  RCNUpdateOptionFetchStatus,
25
};
26
 
27
/// Column names in metadata table
28
static NSString *const RCNKeyBundleIdentifier = @"bundle_identifier";
29
static NSString *const RCNKeyNamespace = @"namespace";
30
static NSString *const RCNKeyFetchTime = @"fetch_time";
31
static NSString *const RCNKeyDigestPerNamespace = @"digest_per_ns";
32
static NSString *const RCNKeyDeviceContext = @"device_context";
33
static NSString *const RCNKeyAppContext = @"app_context";
34
static NSString *const RCNKeySuccessFetchTime = @"success_fetch_time";
35
static NSString *const RCNKeyFailureFetchTime = @"failure_fetch_time";
36
static NSString *const RCNKeyLastFetchStatus = @"last_fetch_status";
37
static NSString *const RCNKeyLastFetchError = @"last_fetch_error";
38
static NSString *const RCNKeyLastApplyTime = @"last_apply_time";
39
static NSString *const RCNKeyLastSetDefaultsTime = @"last_set_defaults_time";
40
 
41
/// Persist config data in sqlite database on device. Managing data read/write from/to database.
42
@interface RCNConfigDBManager : NSObject
43
/// Shared Singleton Instance
44
+ (instancetype)sharedInstance;
45
 
46
/// Database Operation Completion callback.
47
/// @param success Decide whether the DB operation succeeds.
48
/// @param result  Return operation result data.
49
typedef void (^RCNDBCompletion)(BOOL success, NSDictionary *result);
50
 
51
/// Database Load Operation Completion callback.
52
/// @param success Decide whether the DB operation succeeds.
53
/// @param fetchedConfig  Return fetchedConfig loaded from DB
54
/// @param activeConfig  Return activeConfig loaded from DB
55
/// @param defaultConfig  Return defaultConfig loaded from DB
56
typedef void (^RCNDBLoadCompletion)(BOOL success,
57
                                    NSDictionary *fetchedConfig,
58
                                    NSDictionary *activeConfig,
59
                                    NSDictionary *defaultConfig);
60
 
61
/// Returns the current version of the Remote Config database.
62
+ (NSString *)remoteConfigPathForDatabase;
63
 
64
/// Load config content from main table to cached memory during app start.
65
- (void)loadMainWithBundleIdentifier:(NSString *)bundleIdentifier
66
                   completionHandler:(RCNDBLoadCompletion)handler;
67
/// Load config settings for a given namespace from metadata table to cached memory during app
68
/// start. Config settings include success/failure fetch times, device contenxt, app context, etc.
69
- (NSDictionary *)loadMetadataWithBundleIdentifier:(NSString *)bundleIdentifier
70
                                         namespace:(NSString *)namespace;
71
/// Load internal metadata from internal metadata table, such as customized HTTP connection/read
72
/// timeout, throttling time interval and number limit of throttling, etc.
73
/// This call needs to be blocking to ensure throttling works during apps starts.
74
- (NSDictionary *)loadInternalMetadataTable;
75
/// Load experiment from experiment table.
76
/// @param handler    The callback when reading from DB is complete.
77
- (void)loadExperimentWithCompletionHandler:(RCNDBCompletion)handler;
78
/// Load Personalization from table.
79
/// @param handler    The callback when reading from DB is complete.
80
- (void)loadPersonalizationWithCompletionHandler:(RCNDBLoadCompletion)handler;
81
 
82
/// Insert a record in metadata table.
83
/// @param columnNameToValue The column name and its value to be inserted in metadata table.
84
/// @param handler           The callback.
85
- (void)insertMetadataTableWithValues:(NSDictionary *)columnNameToValue
86
                    completionHandler:(RCNDBCompletion)handler;
87
/// Insert a record in main table.
88
/// @param values Values to be inserted.
89
- (void)insertMainTableWithValues:(NSArray *)values
90
                       fromSource:(RCNDBSource)source
91
                completionHandler:(RCNDBCompletion)handler;
92
/// Insert a record in internal metadata table.
93
/// @param values Values to be inserted.
94
- (void)insertInternalMetadataTableWithValues:(NSArray *)values
95
                            completionHandler:(RCNDBCompletion)handler;
96
/// Insert exepriment data in experiment table.
97
/// @param key        The key of experiment data belongs to, which are defined in
98
///                   RCNConfigDefines.h.
99
/// @param value      The value that experiment.
100
/// @param handler    The callback.
101
- (void)insertExperimentTableWithKey:(NSString *)key
102
                               value:(NSData *)value
103
                   completionHandler:(RCNDBCompletion)handler;
104
 
105
- (void)updateMetadataWithOption:(RCNUpdateOption)option
106
                       namespace:(NSString *)namespace
107
                          values:(NSArray *)values
108
               completionHandler:(RCNDBCompletion)handler;
109
 
110
/// Insert or update the data in Personalization config.
111
- (BOOL)insertOrUpdatePersonalizationConfig:(NSDictionary *)metadata fromSource:(RCNDBSource)source;
112
 
113
/// Clear the record of given namespace and package name
114
/// before updating the table.
115
- (void)deleteRecordFromMainTableWithNamespace:(NSString *)namespace_p
116
                              bundleIdentifier:(NSString *)bundleIdentifier
117
                                    fromSource:(RCNDBSource)source;
118
/// Remove all the records of given package name and namespace from metadata/internal metadata DB
119
/// before updating new values from response.
120
- (void)deleteRecordWithBundleIdentifier:(NSString *)bundlerIdentifier
121
                               namespace:(NSString *)namespace
122
                            isInternalDB:(BOOL)isInternalDB;
123
/// Remove all the records from a config content table.
124
- (void)deleteAllRecordsFromTableWithSource:(RCNDBSource)source;
125
 
126
/// Remove all the records from experiment table with given key.
127
/// @param key  The key of experiment data belongs to, which are defined in RCNConfigDefines.h.
128
- (void)deleteExperimentTableForKey:(NSString *)key;
129
 
130
/// Returns true if this a new install of the Config database.
131
- (BOOL)isNewDatabase;
132
@end