title: Swift detect motion activity in background
body: <p>I want to detect motion activity when app is pause (not stop).
  I used this code and it working if user use app:</p>
  
  <pre class="lang-swift prettyprint-override"><code>let isActivityAvailable = CMMotionActivityManager.isActivityAvailable()
  if isActivityAvailable {
      CMMotionActivityManager().startActivityUpdates(to: OperationQueue.main) { (motionActivity) in
          if (motionActivity!.confidence.rawValue &gt; 0) {
              if (motionActivity?.walking)! {
                  print("User is walking")
              }
          }
      }
  }
  </code></pre>