From 0b536cff6d393b4805beaa2d4275173f58f487f0 Mon Sep 17 00:00:00 2001 From: Evgeny Evstropov Date: Sun, 23 Dec 2018 12:12:25 +0300 Subject: [PATCH] copy-right corrects. Decomposition. Fix error message. Fix difference between ios 11 and 10 --- .../RCTAppleHealthKit+Methods_Activity.h | 4 +- .../RCTAppleHealthKit+Methods_Activity.m | 4 +- .../RCTAppleHealthKit+Methods_Body.h | 3 +- .../RCTAppleHealthKit+Methods_Body.m | 3 +- ...RCTAppleHealthKit+Methods_Characteristic.h | 3 +- ...RCTAppleHealthKit+Methods_Characteristic.m | 3 +- .../RCTAppleHealthKit+Methods_Fitness.h | 3 +- .../RCTAppleHealthKit+Methods_Fitness.m | 37 ++++---------- .../RCTAppleHealthKit+Methods_Sleep.h | 3 +- .../RCTAppleHealthKit+Methods_Sleep.m | 3 +- RCTAppleHealthKit/RCTAppleHealthKit+Queries.h | 3 +- RCTAppleHealthKit/RCTAppleHealthKit+Queries.m | 48 +++++++++++-------- .../RCTAppleHealthKit+TypesAndPermissions.h | 3 +- .../RCTAppleHealthKit+TypesAndPermissions.m | 3 +- RCTAppleHealthKit/RCTAppleHealthKit+Utils.h | 4 +- RCTAppleHealthKit/RCTAppleHealthKit+Utils.m | 17 ++++++- RCTAppleHealthKit/RCTAppleHealthKit.h | 3 +- RCTAppleHealthKit/RCTAppleHealthKit.m | 3 +- 18 files changed, 85 insertions(+), 65 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h index 235e9c6..5bdecf4 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h @@ -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) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m index 03b2724..eeb0d91 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m @@ -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" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h index 472829c..0867974 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.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" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m index 7e8b7c6..5a29a89 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m @@ -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" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.h index 6c0adcc..0909ebe 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.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" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m index b7fb4f4..e030b85 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m @@ -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" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h index dcc0238..51449f8 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.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" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m index 8fd935c..9f0e5e2 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m @@ -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]; diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Sleep.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Sleep.h index 3afd6d9..cb71012 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Sleep.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Sleep.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. // #import "RCTAppleHealthKit.h" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Sleep.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Sleep.m index 4b1898f..faba4ed 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Sleep.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Sleep.m @@ -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. // diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.h b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.h index 381a82c..172152b 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.h +++ b/RCTAppleHealthKit/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" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index dc4b572..11ea768 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -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" @@ -56,10 +57,10 @@ ascending:(BOOL)asc limit:(NSUInteger)lim completion:(void (^)(NSArray *, NSError *))completion { - + NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate ascending:asc]; - + // declare the block void (^handlerBlock)(HKSampleQuery *query, NSArray *results, NSError *error); // create and assign the block @@ -70,44 +71,42 @@ } return; } - + if (completion) { NSMutableArray *data = [NSMutableArray arrayWithCapacity:1]; - + dispatch_async(dispatch_get_main_queue(), ^{ - + for (HKQuantitySample *sample in results) { HKQuantity *quantity = sample.quantity; double value = [quantity doubleValueForUnit:unit]; - + NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate]; NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate]; - + NSDictionary *elem = @{ - @"value" : @(value), - @"startDate" : startDateString, - @"endDate" : endDateString, - }; - + @"value" : @(value), + @"startDate" : startDateString, + @"endDate" : endDateString, + }; + [data addObject:elem]; } - + completion(data, error); }); } }; - + HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType predicate:predicate limit:lim sortDescriptors:@[timeSortDescriptor] resultsHandler:handlerBlock]; - + [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]; diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h index f8e3047..d69b7e9 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h +++ b/RCTAppleHealthKit/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" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m index 39e880f..6cb5a05 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m @@ -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" diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Utils.h b/RCTAppleHealthKit/RCTAppleHealthKit+Utils.h index 1f2df83..7d00c78 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Utils.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Utils.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; diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Utils.m b/RCTAppleHealthKit/RCTAppleHealthKit+Utils.m index 505e9ab..8a0c22b 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Utils.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Utils.m @@ -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]; diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.h b/RCTAppleHealthKit/RCTAppleHealthKit.h index eadffd3..6ccbe26 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.h +++ b/RCTAppleHealthKit/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 diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index 90e7872..5ef4ecc 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -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" -- 2.26.2