Skip to content

Commit

Permalink
Fix an error of data-upload process on SQLite
Browse files Browse the repository at this point in the history
Add a force manual upload function
Add an auto-sync controller (On/Off)
  • Loading branch information
tetujin committed Mar 13, 2018
1 parent 162fb73 commit 076e66f
Show file tree
Hide file tree
Showing 40 changed files with 1,595 additions and 1,408 deletions.
Binary file added .DS_Store
Binary file not shown.
70 changes: 45 additions & 25 deletions AWARE.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

28 changes: 20 additions & 8 deletions AWARE/AWAREFramework/Core/AWARECore.m
Expand Up @@ -63,6 +63,7 @@ - (void) activate {
[userDefaults setInteger:1000 * 1000 forKey:KEY_MAX_DATA_SIZE]; // Defualt Value: 1000*1000 (byte) (1000 KB)
[userDefaults setInteger:cleanOldDataTypeAlways forKey:SETTING_FREQUENCY_CLEAN_OLD_DATA];
[userDefaults setInteger:AwareUIModeNormal forKey:SETTING_UI_MODE];
[userDefaults setBool:YES forKey:SETTING_AUTO_SYNC];
[userDefaults setBool:YES forKey:@"aware_inited"];
}
if (![userDefaults boolForKey:@"aware_inited_1.8.2"]) {
Expand All @@ -75,6 +76,12 @@ - (void) activate {
[userDefaults setInteger:cleanOldDataTypeWeekly forKey:SETTING_FREQUENCY_CLEAN_OLD_DATA];
}

if(![userDefaults boolForKey:@"aware_inited_2.1"]){
[userDefaults setBool:YES forKey:@"aware_inited_2.1"];
[userDefaults setInteger:cleanOldDataTypeWeekly forKey:SETTING_FREQUENCY_CLEAN_OLD_DATA];
[userDefaults setBool:YES forKey:SETTING_AUTO_SYNC];
}

if([userDefaults integerForKey:SETTING_DB_TYPE] == AwareDBTypeUnknown){
[userDefaults setInteger:AwareDBTypeCoreData forKey:SETTING_DB_TYPE];
}
Expand All @@ -92,7 +99,9 @@ - (void) activate {

// start sensors
[_sharedSensorManager startAllSensors];
[_sharedSensorManager startUploadTimerWithInterval:uploadInterval];
if([_sharedAwareStudy getAutoSyncState]){
[_sharedSensorManager startUploadTimerWithInterval:uploadInterval];
}
// [self.sharedSensorManager syncAllSensorsWithDBInBackground];

/// Set a timer for a daily sync update
Expand Down Expand Up @@ -145,18 +154,21 @@ - (void) activate {
}

- (void) changedBatteryState:(id) sender{
NSInteger batteryState = [UIDevice currentDevice].batteryState;
if (batteryState == UIDeviceBatteryStateCharging || batteryState == UIDeviceBatteryStateFull) {
Debug * debugSensor = [[Debug alloc] initWithAwareStudy:self.sharedAwareStudy dbType:AwareDBTypeTextFile];
[debugSensor saveDebugEventWithText:@"[Uploader] The battery is charging. AWARE iOS start to upload sensor data." type:DebugTypeInfo label:@""];
[self.sharedSensorManager syncAllSensorsWithDBInBackground];
[self.sharedSensorManager runBatteryStateChangeEvents];
if ([_sharedAwareStudy getAutoSyncState]){
NSInteger batteryState = [UIDevice currentDevice].batteryState;
if (batteryState == UIDeviceBatteryStateCharging || batteryState == UIDeviceBatteryStateFull) {
Debug * debugSensor = [[Debug alloc] initWithAwareStudy:self.sharedAwareStudy dbType:AwareDBTypeTextFile];
[debugSensor saveDebugEventWithText:@"[Uploader] The battery is charging. AWARE iOS start to upload sensor data." type:DebugTypeInfo label:@""];
[self.sharedSensorManager syncAllSensorsWithDBInBackground];
[self.sharedSensorManager runBatteryStateChangeEvents];
}
}
}

- (void) deactivate{
[_sharedSensorManager stopAndRemoveAllSensors];
[_sharedLocationManager stopUpdatingLocation];
[_sharedSensorManager stopUploadTimer];
[_dailyUpdateTimer invalidate];
[_complianceTimer invalidate];
//
Expand Down Expand Up @@ -206,7 +218,7 @@ - (void) initLocationSensor {
CLAuthorizationStatus state = [CLLocationManager authorizationStatus];
if(state == kCLAuthorizationStatusAuthorizedAlways){
// Set a movement threshold for new events.
_sharedLocationManager.distanceFilter = 25; // meters
// _sharedLocationManager.distanceFilter = 25; // meters
[_sharedLocationManager startUpdatingLocation];
[_sharedLocationManager startMonitoringSignificantLocationChanges];
}
Expand Down
2 changes: 1 addition & 1 deletion AWARE/AWAREFramework/Core/AWARECoreDataManager.h
Expand Up @@ -21,7 +21,7 @@ typedef enum: NSInteger {
} AwareDBCondition;


@interface AWARECoreDataManager : AWAREUploader <AWAREDataUploaderDelegate, NSURLSessionDataDelegate, NSURLSessionTaskDelegate>
@interface AWARECoreDataManager : AWAREUploader <AWAREDataUploaderDelegate>

// - (instancetype) initWithAwareStudy:(AWAREStudy *) study sensorName:(NSString *)sensorName dbEntityName:(NSString *) entityName;

Expand Down

0 comments on commit 076e66f

Please sign in to comment.