Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all motion activity into the activity sync class #48

Merged
merged 2 commits into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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