title: Swift CMMotionActivityManager not displaying correct authorization Status
body: <p>I am trying to create a very simple step counter and am following Kamil Wysocki's article at <a href="https://brightinventions.pl/blog/coremotion-pedometer-swift/" rel="nofollow noreferrer">https://brightinventions.pl/blog/coremotion-pedometer-swift/</a>. However, my <code>.isActivityAvailable()</code> is returning False preventing any of my other functions from initiating. Also, my <code>CMMotionActivityManager.authorizationStatus()</code> call is returning 3 (denied). I cannot for the life of me figure out why this is happening. </p>
  
  <p>I have added Motion Usage Description to my info.plist with a description and have enabled authorization on my iPhone simulator. I have also tried simulating the "City walk" mode in the debug menu, which doesn't help.  My code is below.</p>
  
  <pre><code>import UIKit
  import CoreMotion
  import CoreLocation
  
  class ViewController: UIViewController {
  
      @IBOutlet weak var startButton: UIButton!
      @IBOutlet weak var activityTypeLabel: UILabel!
      @IBOutlet weak var stepsCountLabel: UILabel!
  
      private let activityManager = CMMotionActivityManager()
      private let pedometer = CMPedometer()
      private var shouldStartUpdating: Bool = false
      private var startDate: Date? = nil
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          startButton.addTarget(self, action: #selector(didTapStartButton), for: .touchUpInside)
  
      }
  
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
          guard let startDate = startDate else { return }
          updateStepsCountLabelUsing(startDate: startDate)
      }
  
      @objc private func didTapStartButton() {
          shouldStartUpdating = !shouldStartUpdating
          shouldStartUpdating ? (onStart()) : (onStop())
      }
  }
  
  
  extension ViewController {
      private func onStart() {
          startButton.setTitle("Stop", for: .normal)
          startDate = Date()
          checkAuthorizationStatus()
          startUpdating()
      }
  
      private func onStop() {
          startButton.setTitle("Start", for: .normal)
          startDate = nil
          stopUpdating()
      }
  
      private func startUpdating() {
          if CMMotionActivityManager.isActivityAvailable() {
              startTrackingActivityType()
          } else {
              activityTypeLabel.text = "Not available"
          }
  
          if CMPedometer.isStepCountingAvailable() {
              startCountingSteps()
          } else {
              stepsCountLabel.text = "Not available"
          }
      }
  
      private func checkAuthorizationStatus() {
          switch CMMotionActivityManager.authorizationStatus() {
          case CMAuthorizationStatus.denied:
              onStop()
              activityTypeLabel.text = "Not available"
              stepsCountLabel.text = "Not available"
          default:break
          }
      }
  
      private func stopUpdating() {
          activityManager.stopActivityUpdates()
          pedometer.stopUpdates()
          pedometer.stopEventUpdates()
      }
  
      private func on(error: Error) {
          //handle error
      }
  
      private func updateStepsCountLabelUsing(startDate: Date) {
          pedometer.queryPedometerData(from: startDate, to: Date()) {
              [weak self] pedometerData, error in
              if let error = error {
                  self?.on(error: error)
              } else if let pedometerData = pedometerData {
                  DispatchQueue.main.async {
                      self?.stepsCountLabel.text = String(describing: pedometerData.numberOfSteps)
                  }
              }
          }
      }
  
      private func startTrackingActivityType() {
          activityManager.startActivityUpdates(to: OperationQueue.main) {
              [weak self] (activity: CMMotionActivity?) in
              guard let activity = activity else { return }
              DispatchQueue.main.async {
                  if activity.walking {
                      self?.activityTypeLabel.text = "Walking"
                  } else if activity.stationary {
                      self?.activityTypeLabel.text = "Stationary"
                  } else if activity.running {
                      self?.activityTypeLabel.text = "Running"
                  } else if activity.automotive {
                      self?.activityTypeLabel.text = "Automotive"
                  }
              }
          }
      }
  
      private func startCountingSteps() {
          pedometer.startUpdates(from: Date()) {
              [weak self] pedometerData, error in
              guard let pedometerData = pedometerData, error == nil else { return }
  
              DispatchQueue.main.async {
                  self?.stepsCountLabel.text = pedometerData.numberOfSteps.stringValue
              }
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/zfrzX.png" rel="nofollow noreferrer">Here is my viewController upon running and clicking start</a></p>
  
  <p>Big thanks in advance for anyone who can offer any knowledge!!!</p>