From the course: iOS Development: Security

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Request authorization for system features

Request authorization for system features - iOS Tutorial

From the course: iOS Development: Security

Start my 1-month free trial

Request authorization for system features

- [Instructor] We can request authorization to access and share health data via the HKHealthStores request authorization method. First let me stop this. And we're going to implement a private helper method called requestPermission. Private func requestPermission. The method has a completion closure argument. Most Half Kit methods are asynchronous so we need to rely on closures if we built wrappers around them. The completion closure needs to be escaping, and it takes a Boolean argument and an optional error. The Bool indicates whether the authorization is granted and callers can inspect the error parameter to find out what went wrong. Now let's finish the closure and we can start implementing the method. First I need to specify the data type we're going to access, which in our case is the step count. So I'm going to use the Guard statement and use optional binding to create the stepQuantityType which can instantiated using a call to HKObject type quantity type. ObjectType. The…

Contents