Commit 0b536cff authored by Evgeny Evstropov's avatar Evgeny Evstropov

copy-right corrects. Decomposition. Fix error message. Fix difference between ios 11 and 10

parent b1862448
......@@ -3,8 +3,10 @@
// RCTAppleHealthKit
//
// Created by Alexander Vallorosi on 4/27/17.
// Copyright © 2017 Alexander Vallorosi. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit.h"
@interface RCTAppleHealthKit (Methods_Activity)
......
......@@ -3,8 +3,8 @@
// RCTAppleHealthKit
//
// Created by Alexander Vallorosi on 4/27/17.
// Copyright © 2017 Alexander Vallorosi. All rights reserved.
//
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
#import "RCTAppleHealthKit+Methods_Activity.h"
#import "RCTAppleHealthKit+Queries.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit+Methods_Body.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-29.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-29.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit+Methods_Characteristic.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit+Methods_Fitness.h"
......@@ -59,21 +60,11 @@
NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
HKSampleType *samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
if ([type isEqual:@"Walking"]) {
samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
} else if ([type isEqual:@"StairClimbing"]) {
samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed];
} else if ([type isEqual:@"Running"]){
samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
HKSampleType *samplesType = [RCTAppleHealthKit hkQuantityTypeFromString:type];
if ([type isEqual:@"Running"] || [type isEqual:@"Cycling"]) {
unit = [HKUnit mileUnit];
} else if ([type isEqual:@"Cycling"]){
samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling];
unit = [HKUnit mileUnit];
} else if ([type isEqual:@"Workout"]){
samplesType = [HKObjectType workoutType];
}
NSLog(@"error getting samples: %@", [samplesType identifier]);
[self fetchSamplesOfType:samplesType
unit:unit
predicate:predicate
......@@ -84,8 +75,8 @@
callback(@[[NSNull null], results]);
return;
} else {
NSLog(@"error getting active energy burned samples: %@", error);
callback(@[RCTMakeError(@"error getting active energy burned samples", nil, nil)]);
NSLog(@"error getting samples: %@", error);
callback(@[RCTMakeError(@"error getting samples", nil, nil)]);
return;
}
}];
......@@ -96,19 +87,9 @@
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]];
NSString *type = [RCTAppleHealthKit stringFromOptions:input key:@"type" withDefault:@"Walking"];
HKSampleType *samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
if ([type isEqual:@"Walking"]) {
samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
} else if ([type isEqual:@"StairClimbing"]) {
samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed];
} else if ([type isEqual:@"Running"]){
samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
unit = [HKUnit mileUnit];
} else if ([type isEqual:@"Cycling"]){
samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling];
HKSampleType *samplesType = [RCTAppleHealthKit hkQuantityTypeFromString:type];
if ([type isEqual:@"Running"] || [type isEqual:@"Cycling"]) {
unit = [HKUnit mileUnit];
} else if ([type isEqual:@"Workout"]){
samplesType = [HKObjectType workoutType];
}
[self setObserverForType:samplesType unit:unit];
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-11-06.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-11-06.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit+Queries.h"
......@@ -106,8 +107,6 @@
[self.healthStore executeQuery:query];
}
- (void)fetchSamplesOfType:(HKSampleType *)type
unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate
......@@ -146,13 +145,23 @@
isTracked = false;
}
NSString* device = @"";
if (@available(iOS 11.0, *)) {
device = [[sample sourceRevision] productType];
} else {
device = [[sample device] name];
if (!device) {
device = @"iPhone";
}
}
NSDictionary *elem = @{
@"activityName" : [NSNumber numberWithInt:[sample workoutActivityType]],
@"calories" : @(energy),
@"tracked" : @(isTracked),
@"sourceName" : [[[sample sourceRevision] source] name],
@"sourceId" : [[[sample sourceRevision] source] bundleIdentifier],
@"device": [[sample sourceRevision] productType],
@"device": device,
@"distance" : @(distance),
@"start" : startDateString,
@"end" : endDateString
......@@ -244,7 +253,6 @@
limit:(NSUInteger)lim
completion:(void (^)(NSArray *, NSError *))completion {
NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate
ascending:false];
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit+TypesAndPermissions.h"
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit.h"
......@@ -22,6 +23,7 @@
+ (NSDate *)startDateFromOptions:(NSDictionary *)options;
+ (NSDate *)endDateFromOptions:(NSDictionary *)options;
+ (NSDate *)endDateFromOptionsDefaultNow:(NSDictionary *)options;
+ (HKSampleType *)hkQuantityTypeFromString:(NSString *)type;
+ (HKUnit *)hkUnitFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(HKUnit *)defaultValue;
+ (NSUInteger)uintFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(NSUInteger)defaultValue;
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit+Utils.h"
......@@ -123,6 +124,20 @@
return date;
}
+ (HKSampleType *)hkQuantityTypeFromString:(NSString *)type {
if ([type isEqual:@"Walking"]) {
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
} else if ([type isEqual:@"StairClimbing"]) {
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed];
} else if ([type isEqual:@"Running"]){
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
} else if ([type isEqual:@"Cycling"]){
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling];
}
// default [type isEqual:@"Workout"])
return [HKObjectType workoutType];
}
+ (HKUnit *)hkUnitFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(HKUnit *)defaultValue {
NSString *unitString = [options objectForKey:key];
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import <Foundation/Foundation.h>
......
......@@ -3,7 +3,8 @@
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "RCTAppleHealthKit.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment