Skip to content

Commit

Permalink
Merge pull request #48 from shankari/master
Browse files Browse the repository at this point in the history
Move all motion activity into the activity sync class
  • Loading branch information
shankari committed Jun 5, 2021
2 parents 5545455 + 4ae780f commit 32f0111
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-em-serversync",
"version": "1.2.4",
"version": "1.2.5",
"description": "Simple package that stores all the connection settings that need to be configured",
"license": "BSD-3-clause",
"cordova": {
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="cordova-plugin-em-serversync"
version="1.2.4">
version="1.2.5">

<name>ServerSync</name>
<description>Push and pull local data to the server</description>
Expand Down
1 change: 1 addition & 0 deletions src/ios/BEMActivitySync.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
typedef void (^CombinedArrayHandler)(NSArray* combinedArrayHandler);

@interface BEMActivitySync: NSObject
+ (void) initWithConsent;
+ (void) getCombinedArray:(NSArray*)locationArray withHandler:(CombinedArrayHandler)completionArray;
@end
28 changes: 28 additions & 0 deletions src/ios/BEMActivitySync.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,41 @@
#import "BEMBuiltinUserCache.h"
#import "SimpleLocation.h"
#import "TimeQuery.h"
#import "TripDiarySettingsCheck.h"
#import "MotionActivity.h"
#import "BEMServerSyncCommunicationHelper.h"
#import "LocationTrackingConfig.h"
#import <CoreMotion/CoreMotion.h>

@implementation BEMActivitySync

+ (void) initWithConsent {
CMMotionActivityManager* activityMgr = [[CMMotionActivityManager alloc] init];
NSOperationQueue* mq = [NSOperationQueue mainQueue];
NSDate* startDate = [NSDate new];
NSTimeInterval dayAgoSecs = 24 * 60 * 60;
NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow:-(dayAgoSecs)];
[activityMgr queryActivityStartingFromDate:startDate toDate:endDate toQueue:mq withHandler:^(NSArray *activities, NSError *error) {
if (error == nil) {
[LocalNotificationManager addNotification:@"activity recognition works fine"];
} else {
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"Error %@ while reading activities, travel mode detection may be unavailable", error]];
NSString* title = NSLocalizedStringFromTable(@"error-reading-activities", @"DCLocalizable", nil);
NSString* message = NSLocalizedStringFromTable(@"travel-mode-unavailable", @"DCLocalizable", nil);

UIAlertController* alert = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[TripDiarySettingsCheck showSettingsAlert:alert];
}
}];
}

+ (void) getCombinedArray:(NSArray*) locationArray withHandler:(CombinedArrayHandler)completionHandler {
/*
* In iOS, we can only sign up for activity updates when the app is in the foreground
Expand Down

0 comments on commit 32f0111

Please sign in to comment.