Apple HealthKit setHealthStore is not working

I am making an app that fetches the data from HealthKit. I have downloaded the apple example of the HealthKit app, and it was working well, until I changed the structure of the app, and made a Navigation View Controller my root view controller (instead of TabBarViewController like it was in the example). So now I do not get list of the types of the data that my user needs to share and the following piece of code in my ViewController never gets executed:

[self.healthStore requestAuthorizationToShareTypes:writeDataTypes readTypes:readDataTypes completion:^(BOOL success, NSError *error) {...}

I think I found a place where it goes wrong. In the AppDelegate.m I need to set up the HealthStore for all view controllers that are going to be presented to the user. So the original apple code was like this:

- (void)setUpHealthStoreForTabBarControllers { UITabBarController *tabBarController = (UITabBarController *)[self.window rootViewController]; for (UINavigationController *navigationController in tabBarController.viewControllers) { id viewController = navigationController.topViewController; if ([viewController respondsToSelector:@selector(setHealthStore:)]) { [viewController setHealthStore:self.healthStore]; } } }

Because I changed my root view controller to the NavigationViewController: Apple HealthKit setHealthStore is not working

I also need to modify AppDelegate's method set healthkit somehow like this:

- (void)setUpHealthStoreForTabBarControllers { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle: nil]; UITabBarController *tabvc = [storyboard instantiateViewControllerWithIdentifier:@"thisAndThat"]; for (UINavigationController *navigationController in tabvc.viewControllers) { id viewController = navigationController.topViewController; if ([viewController respondsToSelector:@selector(setHealthStore:)]) { NSLog(@"0000000000000 -responds-"); [viewController setHealthStore:self.healthStore]; } } }

I am simply getting my TabBarController with storyboard id. It does iterate 5 times inside the loop (like it does originally, if I set up the root back to TabBar like so:

Apple HealthKit setHealthStore is not working

and I get the same tabBarController as in my case with the storyboard id. But in my case I can not get the sharing permissions sheet of HealthKit. What am I doing wrong?

Category:ios Views:4 Time:2019-02-09

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.164 (s). 11 q(s)