28 _mDateFormatter = [[NSDateFormatter alloc] init];
29 [_mDateFormatter setDateStyle:NSDateFormatterMediumStyle];
30 [_mDateFormatter setTimeStyle:NSDateFormatterNoStyle];
33 UIImage *backgrdImage = [UIImage imageNamed:@"HealthKit.png"];
34 CGSize photoSize = [backgrdImage size];
35 CGRect totalFrame =
self.view.frame;
36 float resizeRatio = photoSize.width / totalFrame.size.width;
37 UIImage *resizedImage = [UIImage imageWithCGImage:[backgrdImage CGImage]
38 scale:backgrdImage.scale * resizeRatio
39 orientation:(backgrdImage.imageOrientation) ];
40 UIImageView *backgrd = [[UIImageView alloc] initWithImage:resizedImage];
41 [
self.view addSubview:backgrd];
45 self.tableView.delegate =
self;
46 self.tableView.dataSource =
self;
50 Boolean needsAdditionalAuthority = NO;
51 for (NSString *param in [localData establishNutritionParameters]) {
52 HKQuantityType *rowQuantityType = [HKObjectType quantityTypeForIdentifier:param];
53 [needAuthorizationSet addObject:rowQuantityType];
54 needsAdditionalAuthority = YES;
56 NSString *shortName = [param substringFromIndex:31];
58 [componentsAuthorityStatus addObject:authorityEntry];
67 for (NSString *param in [localData establishNutritionParameters]) {
69 HKQuantityType *rowQuantityType = [HKObjectType quantityTypeForIdentifier:param];
72 if (rowQuantityType) {
74 NSLog(
@"healthKitView.viewDidLoad: param: %@ shareOk: %@", param, shareOK);
77 [
self.tableView reloadData];
80 #pragma mark - UITableViewDataSource 81 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
90 NSInteger nSections = [authorityConditionArray count];
91 NSLog(
@"healthKitView.numberOfSectionsInTableView: nSections: %ld", (
long)nSections);
94 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
96 NSLog(
@"healthKitView.numberOfSectionsInTableView");
99 NSArray *sectionComponentCount = [sectionDictionary objectForKey:@"HKAuthority-status-types"];
100 NSInteger sectionCount = [sectionComponentCount count];
101 NSLog(
@"healthKitView.numberOfSectionsInTableView: sectionCount: %ld", (
long)sectionCount);
104 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
107 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"health-kit-categories"];
109 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"health-kit-categories"];
114 NSString *detailCaption;
116 NSArray *sectionItems = [sectionDictionary objectForKey:@"HKAuthority-status-types"];
117 if ([indexPath row] < [sectionItems count]) {
121 NSDictionary *rowInfo = [sectionItems objectAtIndex:[indexPath row]];
122 caption = [rowInfo objectForKey:@"component-name"];
123 NSDate *authorityDate = [rowInfo objectForKey:@"component-authority-date"];
124 detailCaption = [_mDateFormatter stringFromDate:authorityDate];
134 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
137 NSString *sectionName = [sectionDictionary objectForKey:@"HKAuthority-status-ident"];
141 #pragma mark - UITableVIewDelegate 142 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
146 NSLog(
@"HealthKitVIew.didSelectRow: section: %ld row: %ld\nset: %@", (
long)[indexPath section], (
long)[indexPath row],
needAuthorizationSet);
153 #pragma mark - Z5HealthConnectionProtocol 154 - (void) healthQuantityTypeData: (HKQuantityType *)quantityType success: (Boolean) flag
171 int notDetermined = 0;
173 int itemAuthorized = 0;
174 NSMutableArray<NSMutableDictionary *> *notDeterminedTypes = [[NSMutableArray alloc] init];
175 NSMutableArray<NSMutableDictionary *> *deniedTypes = [[NSMutableArray alloc] init];
176 NSMutableArray<NSMutableDictionary *> *allowedTypes = [[NSMutableArray alloc] init];
184 NSMutableDictionary *componentData = [[NSMutableDictionary alloc] init];
185 [componentData setObject:nameData forKey:@"component-name"];
186 [componentData setObject:dateData forKey:@"component-authority-date"];
188 HKAuthorizationStatus status = [authorityData integerValue];
190 case HKAuthorizationStatusNotDetermined:
192 [notDeterminedTypes addObject:componentData];
195 case HKAuthorizationStatusSharingDenied:
197 [deniedTypes addObject:componentData];
200 case HKAuthorizationStatusSharingAuthorized:
202 [allowedTypes addObject:componentData];
207 NSMutableArray<NSDictionary *> *ret = [[NSMutableArray alloc] initWithCapacity:3];
208 NSNumber *statusNumb;
209 if (0 < notDetermined)
211 statusNumb = [NSNumber numberWithInt:HKAuthorizationStatusNotDetermined];
213 NSArray *statusTypes = [[NSArray alloc] initWithArray:notDeterminedTypes];
214 NSDictionary *notDeterminedElement = [[NSDictionary alloc] initWithObjectsAndKeys:@"not deteermined", @"HKAuthority-status-ident", statusTypes, @"HKAuthority-status-types", nil];
215 [ret addObject:notDeterminedElement];
219 statusNumb = [NSNumber numberWithInt:HKAuthorizationStatusSharingDenied];
221 NSArray *statusTypes = [[NSArray alloc] initWithArray:deniedTypes];
222 NSDictionary *sharingDeniedElement = [[NSDictionary alloc] initWithObjectsAndKeys:@"denied", @"HKAuthority-status-ident", statusTypes, @"HKAuthority-status-types", nil];
223 [ret addObject:sharingDeniedElement];
225 if (0 < itemAuthorized)
227 statusNumb = [NSNumber numberWithInt:HKAuthorizationStatusSharingAuthorized];
229 NSArray *statusTypes = [[NSArray alloc] initWithArray:allowedTypes];
230 NSDictionary *sharingApprovedElement = [[NSDictionary alloc] initWithObjectsAndKeys:@"authorized", @"HKAuthority-status-ident", statusTypes, @"HKAuthority-status-types", nil];
231 [ret addObject:sharingApprovedElement];
239 [
super didReceiveMemoryWarning];
void didReceiveMemoryWarning()
NSMutableSet * needAuthorizationSet
NSString * componentNameKey()
NSArray< NSDictionary *> * authorityConditionSections()
NSString * componentAuthorityDateKey()
instancetype sharedInstance()
NSMutableArray< NSDictionary * > * componentsAuthorityStatus
NSDateFormatter * mDateFormatter
NSMutableArray< NSDictionary * > * updatedAuthorityStatus
void updateToAuthorizationOK()
NSString * componentAuthorityKey()
NSNumber * checkTypeAuthorization:(HKQuantityType *quantityType)
Singleton interface to both core and remote data sources.
NSMutableArray * annotateAuthority:(NSArray *componentArray)
void labelizeCell:withText:inColor:andDetail:(UITableViewCell *targCell, [withText] NSString *txt, [inColor] UIColor *color, [andDetail] NSString *detailTxt)