Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rn-apple-healthkit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ym
rn-apple-healthkit
Commits
03974dae
Commit
03974dae
authored
Jun 26, 2016
by
Greg Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created Utils category and refactored
parent
2e1a9fa6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
21 deletions
+78
-21
RCTAppleHealthKit.xcodeproj/project.pbxproj
RCTAppleHealthKit.xcodeproj/project.pbxproj
+6
-0
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
+0
-1
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
+3
-20
RCTAppleHealthKit/RCTAppleHealthKit+Utils.h
RCTAppleHealthKit/RCTAppleHealthKit+Utils.h
+18
-0
RCTAppleHealthKit/RCTAppleHealthKit+Utils.m
RCTAppleHealthKit/RCTAppleHealthKit+Utils.m
+50
-0
RCTAppleHealthKit/RCTAppleHealthKit.m
RCTAppleHealthKit/RCTAppleHealthKit.m
+1
-0
No files found.
RCTAppleHealthKit.xcodeproj/project.pbxproj
View file @
03974dae
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
3774C8931D2092F20000B3F3
/* RCTAppleHealthKit.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3774C8921D2092F20000B3F3
/* RCTAppleHealthKit.m */
;
};
3774C8931D2092F20000B3F3
/* RCTAppleHealthKit.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3774C8921D2092F20000B3F3
/* RCTAppleHealthKit.m */
;
};
3774C89B1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3774C89A1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m */
;
};
3774C89B1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3774C89A1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m */
;
};
3774C89E1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3774C89D1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m */
;
};
3774C89E1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3774C89D1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m */
;
};
3774C8A11D20A6B90000B3F3
/* RCTAppleHealthKit+Utils.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3774C8A01D20A6B90000B3F3
/* RCTAppleHealthKit+Utils.m */
;
};
/* End PBXBuildFile section */
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
/* Begin PBXCopyFilesBuildPhase section */
...
@@ -34,6 +35,8 @@
...
@@ -34,6 +35,8 @@
3774C89A1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"RCTAppleHealthKit+Queries.m"
;
sourceTree
=
"<group>"
;
};
3774C89A1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"RCTAppleHealthKit+Queries.m"
;
sourceTree
=
"<group>"
;
};
3774C89C1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
"RCTAppleHealthKit+TypesAndPermissions.h"
;
sourceTree
=
"<group>"
;
};
3774C89C1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
"RCTAppleHealthKit+TypesAndPermissions.h"
;
sourceTree
=
"<group>"
;
};
3774C89D1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"RCTAppleHealthKit+TypesAndPermissions.m"
;
sourceTree
=
"<group>"
;
};
3774C89D1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"RCTAppleHealthKit+TypesAndPermissions.m"
;
sourceTree
=
"<group>"
;
};
3774C89F1D20A6B90000B3F3
/* RCTAppleHealthKit+Utils.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
"RCTAppleHealthKit+Utils.h"
;
sourceTree
=
"<group>"
;
};
3774C8A01D20A6B90000B3F3
/* RCTAppleHealthKit+Utils.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"RCTAppleHealthKit+Utils.m"
;
sourceTree
=
"<group>"
;
};
/* End PBXFileReference section */
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
/* Begin PBXFrameworksBuildPhase section */
...
@@ -72,6 +75,8 @@
...
@@ -72,6 +75,8 @@
3774C89A1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m */
,
3774C89A1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m */
,
3774C89C1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.h */
,
3774C89C1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.h */
,
3774C89D1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m */
,
3774C89D1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m */
,
3774C89F1D20A6B90000B3F3
/* RCTAppleHealthKit+Utils.h */
,
3774C8A01D20A6B90000B3F3
/* RCTAppleHealthKit+Utils.m */
,
);
);
path
=
RCTAppleHealthKit
;
path
=
RCTAppleHealthKit
;
sourceTree
=
"<group>"
;
sourceTree
=
"<group>"
;
...
@@ -133,6 +138,7 @@
...
@@ -133,6 +138,7 @@
buildActionMask
=
2147483647
;
buildActionMask
=
2147483647
;
files
=
(
files
=
(
3774C89B1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m in Sources */
,
3774C89B1D2095450000B3F3
/* RCTAppleHealthKit+Queries.m in Sources */
,
3774C8A11D20A6B90000B3F3
/* RCTAppleHealthKit+Utils.m in Sources */
,
3774C8931D2092F20000B3F3
/* RCTAppleHealthKit.m in Sources */
,
3774C8931D2092F20000B3F3
/* RCTAppleHealthKit.m in Sources */
,
3774C89E1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m in Sources */
,
3774C89E1D2095850000B3F3
/* RCTAppleHealthKit+TypesAndPermissions.m in Sources */
,
);
);
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
View file @
03974dae
...
@@ -12,6 +12,5 @@
...
@@ -12,6 +12,5 @@
-
(
void
)
fetchMostRecentQuantitySampleOfType
:(
HKQuantityType
*
)
quantityType
predicate
:(
NSPredicate
*
)
predicate
completion
:(
void
(
^
)(
HKQuantity
*
mostRecentQuantity
,
NSError
*
error
))
completion
;
-
(
void
)
fetchMostRecentQuantitySampleOfType
:(
HKQuantityType
*
)
quantityType
predicate
:(
NSPredicate
*
)
predicate
completion
:(
void
(
^
)(
HKQuantity
*
mostRecentQuantity
,
NSError
*
error
))
completion
;
-
(
void
)
fetchSumOfSamplesTodayForType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
completion
:(
void
(
^
)(
double
,
NSError
*
))
completionHandler
;
-
(
void
)
fetchSumOfSamplesTodayForType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
completion
:(
void
(
^
)(
double
,
NSError
*
))
completionHandler
;
-
(
NSPredicate
*
)
predicateForSamplesToday
;
@end
@end
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
View file @
03974dae
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
//
//
#import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+Utils.h"
@implementation
RCTAppleHealthKit
(
Queries
)
@implementation
RCTAppleHealthKit
(
Queries
)
...
@@ -35,14 +36,14 @@
...
@@ -35,14 +36,14 @@
completion
(
quantity
,
error
);
completion
(
quantity
,
error
);
}
}
}];
}];
[
self
.
healthStore
executeQuery
:
query
];
[
self
.
healthStore
executeQuery
:
query
];
}
}
-
(
void
)
fetchSumOfSamplesTodayForType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
completion
:(
void
(
^
)(
double
,
NSError
*
))
completionHandler
{
-
(
void
)
fetchSumOfSamplesTodayForType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
completion
:(
void
(
^
)(
double
,
NSError
*
))
completionHandler
{
NSPredicate
*
predicate
=
[
self
predicateForSamplesToday
];
NSPredicate
*
predicate
=
[
RCTAppleHealthKit
predicateForSamplesToday
];
HKStatisticsQuery
*
query
=
[[
HKStatisticsQuery
alloc
]
initWithQuantityType
:
quantityType
quantitySamplePredicate
:
predicate
options
:
HKStatisticsOptionCumulativeSum
completionHandler
:^
(
HKStatisticsQuery
*
query
,
HKStatistics
*
result
,
NSError
*
error
)
{
HKStatisticsQuery
*
query
=
[[
HKStatisticsQuery
alloc
]
initWithQuantityType
:
quantityType
quantitySamplePredicate
:
predicate
options
:
HKStatisticsOptionCumulativeSum
completionHandler
:^
(
HKStatisticsQuery
*
query
,
HKStatistics
*
result
,
NSError
*
error
)
{
HKQuantity
*
sum
=
[
result
sumQuantity
];
HKQuantity
*
sum
=
[
result
sumQuantity
];
...
@@ -57,22 +58,4 @@
...
@@ -57,22 +58,4 @@
[
self
.
healthStore
executeQuery
:
query
];
[
self
.
healthStore
executeQuery
:
query
];
}
}
#pragma mark - Convenience
-
(
NSPredicate
*
)
predicateForSamplesToday
{
NSCalendar
*
calendar
=
[
NSCalendar
currentCalendar
];
NSDate
*
now
=
[
NSDate
date
];
NSDate
*
startDate
=
[
calendar
startOfDayForDate
:
now
];
NSDate
*
endDate
=
[
calendar
dateByAddingUnit
:
NSCalendarUnitDay
value
:
1
toDate
:
startDate
options
:
0
];
return
[
HKQuery
predicateForSamplesWithStartDate
:
startDate
endDate
:
endDate
options
:
HKQueryOptionStrictStartDate
];
}
@end
@end
RCTAppleHealthKit/RCTAppleHealthKit+Utils.h
0 → 100644
View file @
03974dae
//
// RCTAppleHealthKit+Utils.h
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
//
#import "RCTAppleHealthKit.h"
@interface
RCTAppleHealthKit
(
Utils
)
+
(
NSDate
*
)
parseISO8601DateFromString
:(
NSString
*
)
date
;
+
(
NSString
*
)
buildISO8601StringFromDate
:(
NSDate
*
)
date
;
+
(
NSPredicate
*
)
predicateForSamplesToday
;
+
(
NSPredicate
*
)
predicateForSamplesOnDay
:(
NSDate
*
)
date
;
+
(
NSPredicate
*
)
predicateForSamplesOnDayFromTimestamp
:(
NSString
*
)
timestamp
;
@end
RCTAppleHealthKit/RCTAppleHealthKit+Utils.m
0 → 100644
View file @
03974dae
//
// RCTAppleHealthKit+Utils.m
// RCTAppleHealthKit
//
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
//
#import "RCTAppleHealthKit+Utils.h"
@implementation
RCTAppleHealthKit
(
Utils
)
#pragma mark - Utilities
+
(
NSDate
*
)
parseISO8601DateFromString
:(
NSString
*
)
date
{
NSDateFormatter
*
dateFormatter
=
[
NSDateFormatter
new
];
NSLocale
*
posix
=
[
NSLocale
localeWithLocaleIdentifier
:
@"en_US_POSIX"
];
dateFormatter
.
locale
=
posix
;
dateFormatter
.
dateFormat
=
@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"
;
return
[
dateFormatter
dateFromString
:
date
];
}
+
(
NSString
*
)
buildISO8601StringFromDate
:(
NSDate
*
)
date
{
NSDateFormatter
*
dateFormatter
=
[
NSDateFormatter
new
];
NSLocale
*
posix
=
[
NSLocale
localeWithLocaleIdentifier
:
@"en_US_POSIX"
];
dateFormatter
.
locale
=
posix
;
dateFormatter
.
dateFormat
=
@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"
;
return
[
dateFormatter
stringFromDate
:
date
];
}
+
(
NSPredicate
*
)
predicateForSamplesToday
{
NSDate
*
now
=
[
NSDate
date
];
return
[
RCTAppleHealthKit
predicateForSamplesOnDay
:
now
];
}
+
(
NSPredicate
*
)
predicateForSamplesOnDayFromTimestamp
:(
NSString
*
)
timestamp
{
NSDate
*
day
=
[
RCTAppleHealthKit
parseISO8601DateFromString
:
timestamp
];
return
[
RCTAppleHealthKit
predicateForSamplesOnDay
:
day
];
}
+
(
NSPredicate
*
)
predicateForSamplesOnDay
:(
NSDate
*
)
date
{
NSCalendar
*
calendar
=
[
NSCalendar
currentCalendar
];
NSDate
*
startDate
=
[
calendar
startOfDayForDate
:
date
];
NSDate
*
endDate
=
[
calendar
dateByAddingUnit
:
NSCalendarUnitDay
value
:
1
toDate
:
startDate
options
:
0
];
return
[
HKQuery
predicateForSamplesWithStartDate
:
startDate
endDate
:
endDate
options
:
HKQueryOptionStrictStartDate
];
}
@end
RCTAppleHealthKit/RCTAppleHealthKit.m
View file @
03974dae
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#import "RCTAppleHealthKit.h"
#import "RCTAppleHealthKit.h"
#import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+TypesAndPermissions.h"
#import "RCTAppleHealthKit+TypesAndPermissions.h"
#import "RCTAppleHealthKit+Utils.h"
@implementation
RCTAppleHealthKit
@implementation
RCTAppleHealthKit
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment