Example project for HealthKit
- use PromiseKit
- write data
A Series of HealthKit Demo.
pod install
- Input data
- Save data
Promise wrapper of HKHealthStore
.
@interface DataStoreManager : NSObject
@property(nonatomic, strong) HKHealthStore *healthStore;
// authorizationToType + authorizationStatusForType
- (PMKPromise *)availableType:(HKQuantityType *) hkQuantity;
- (PMKPromise *)authorizationToType:(HKQuantityType *) hkQuantity;
- (PMKPromise *)authorizationStatusForType:(HKQuantityType *) quantityType;
- (PMKPromise *)writeSample:(HKQuantitySample *)sample;
@end
Smart control flow by used that.
PMKPromise *availableTypePromise = [self.dataStoreManager availableType:self.model.managedType];
availableTypePromise.then(^{
return [self.dataStoreManager writeSample:self.model.heightSample];
}).then(^{
UIAlertView *savedAlert = [[UIAlertView alloc] initWithTitle:nil message:@"Saved!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[savedAlert show];
}).catch(^(NSError *error) {
UIAlertView *savedAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[savedAlert show];
NSLog(@"error = %@", error);
});
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
MIT