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 @@ ...@@ -3,8 +3,10 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Alexander Vallorosi on 4/27/17. // 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" #import "RCTAppleHealthKit.h"
@interface RCTAppleHealthKit (Methods_Activity) @interface RCTAppleHealthKit (Methods_Activity)
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Alexander Vallorosi on 4/27/17. // 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+Methods_Activity.h"
#import "RCTAppleHealthKit+Queries.h" #import "RCTAppleHealthKit+Queries.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit+Methods_Body.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-29. // 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" #import "RCTAppleHealthKit.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-29. // 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" #import "RCTAppleHealthKit+Methods_Characteristic.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit+Methods_Fitness.h"
...@@ -59,21 +60,11 @@ ...@@ -59,21 +60,11 @@
NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate]; NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
HKSampleType *samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; HKSampleType *samplesType = [RCTAppleHealthKit hkQuantityTypeFromString:type];
if ([type isEqual:@"Walking"]) { if ([type isEqual:@"Running"] || [type isEqual:@"Cycling"]) {
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]; 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 [self fetchSamplesOfType:samplesType
unit:unit unit:unit
predicate:predicate predicate:predicate
...@@ -84,8 +75,8 @@ ...@@ -84,8 +75,8 @@
callback(@[[NSNull null], results]); callback(@[[NSNull null], results]);
return; return;
} else { } else {
NSLog(@"error getting active energy burned samples: %@", error); NSLog(@"error getting samples: %@", error);
callback(@[RCTMakeError(@"error getting active energy burned samples", nil, nil)]); callback(@[RCTMakeError(@"error getting samples", nil, nil)]);
return; return;
} }
}]; }];
...@@ -96,19 +87,9 @@ ...@@ -96,19 +87,9 @@
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]]; HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]];
NSString *type = [RCTAppleHealthKit stringFromOptions:input key:@"type" withDefault:@"Walking"]; NSString *type = [RCTAppleHealthKit stringFromOptions:input key:@"type" withDefault:@"Walking"];
HKSampleType *samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; HKSampleType *samplesType = [RCTAppleHealthKit hkQuantityTypeFromString:type];
if ([type isEqual:@"Walking"]) { if ([type isEqual:@"Running"] || [type isEqual:@"Cycling"]) {
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];
unit = [HKUnit mileUnit]; unit = [HKUnit mileUnit];
} else if ([type isEqual:@"Workout"]){
samplesType = [HKObjectType workoutType];
} }
[self setObserverForType:samplesType unit:unit]; [self setObserverForType:samplesType unit:unit];
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-11-06. // 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" #import "RCTAppleHealthKit.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-11-06. // 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 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit+Queries.h"
...@@ -106,8 +107,6 @@ ...@@ -106,8 +107,6 @@
[self.healthStore executeQuery:query]; [self.healthStore executeQuery:query];
} }
- (void)fetchSamplesOfType:(HKSampleType *)type - (void)fetchSamplesOfType:(HKSampleType *)type
unit:(HKUnit *)unit unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate predicate:(NSPredicate *)predicate
...@@ -146,13 +145,23 @@ ...@@ -146,13 +145,23 @@
isTracked = false; isTracked = false;
} }
NSString* device = @"";
if (@available(iOS 11.0, *)) {
device = [[sample sourceRevision] productType];
} else {
device = [[sample device] name];
if (!device) {
device = @"iPhone";
}
}
NSDictionary *elem = @{ NSDictionary *elem = @{
@"activityName" : [NSNumber numberWithInt:[sample workoutActivityType]], @"activityName" : [NSNumber numberWithInt:[sample workoutActivityType]],
@"calories" : @(energy), @"calories" : @(energy),
@"tracked" : @(isTracked), @"tracked" : @(isTracked),
@"sourceName" : [[[sample sourceRevision] source] name], @"sourceName" : [[[sample sourceRevision] source] name],
@"sourceId" : [[[sample sourceRevision] source] bundleIdentifier], @"sourceId" : [[[sample sourceRevision] source] bundleIdentifier],
@"device": [[sample sourceRevision] productType], @"device": device,
@"distance" : @(distance), @"distance" : @(distance),
@"start" : startDateString, @"start" : startDateString,
@"end" : endDateString @"end" : endDateString
...@@ -244,7 +253,6 @@ ...@@ -244,7 +253,6 @@
limit:(NSUInteger)lim limit:(NSUInteger)lim
completion:(void (^)(NSArray *, NSError *))completion { completion:(void (^)(NSArray *, NSError *))completion {
NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate
ascending:false]; ascending:false];
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit+TypesAndPermissions.h"
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit.h"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
+ (NSDate *)startDateFromOptions:(NSDictionary *)options; + (NSDate *)startDateFromOptions:(NSDictionary *)options;
+ (NSDate *)endDateFromOptions:(NSDictionary *)options; + (NSDate *)endDateFromOptions:(NSDictionary *)options;
+ (NSDate *)endDateFromOptionsDefaultNow:(NSDictionary *)options; + (NSDate *)endDateFromOptionsDefaultNow:(NSDictionary *)options;
+ (HKSampleType *)hkQuantityTypeFromString:(NSString *)type;
+ (HKUnit *)hkUnitFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(HKUnit *)defaultValue; + (HKUnit *)hkUnitFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(HKUnit *)defaultValue;
+ (NSUInteger)uintFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(NSUInteger)defaultValue; + (NSUInteger)uintFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(NSUInteger)defaultValue;
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #import "RCTAppleHealthKit+Utils.h"
...@@ -123,6 +124,20 @@ ...@@ -123,6 +124,20 @@
return date; 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 { + (HKUnit *)hkUnitFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(HKUnit *)defaultValue {
NSString *unitString = [options objectForKey:key]; NSString *unitString = [options objectForKey:key];
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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> #import <Foundation/Foundation.h>
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // 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" #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