FAQ Database Discussion Community

CoreMotion Basic

import UIKit import CoreMotion class ViewController: UIViewController { @IBOutlet weak var label: UILabel! override func viewDidLoad() { super.viewDidLoad() let manager = CMMotionManager() if manager.accelerometerAvailable { println("accelerometerAvailable = true") manager.accelerometerUpdateInterval = 0.01 manager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue()) { [weak self] (data: CMAccelerometerData!, error: NSError!) in println("inside") println(data) println("x: \(data.acceleration.x)") println("y:...

Fetch/Refresh Health Kit Data Programmatically?

When you open the Health app, it updates it's values from somewhere, but if you don't actually open the app, the Healthkit only seems to update randomly (and very scarsely). For example, Step data objects don't get pulled from (wherever the iOS source comes from) or the Apple Watch until...

How to get Acceleration Time & Acceleration Magnitude in iPhone

Currently I'm trying to use CMAcceleration to get accelerometer values for x,y& z axis is it possible to get Acceleration Time & Acceleration Magnitude with this x,y & z values.When i checked the developer forum i can't find any delegates / methods to get this two.Guide me to find the...

Apple watch standup detection

I am now working on a app dealing with user's motion on the Apple watch. As shown on the Apple Watch, it recognize when you are sitting or standing. Is there any way to get access to it using API? Thanks

startAccelerometerUpdatesToQueue Type of expression is ambiguous without more context

I am trying to translate the following code to Swift 2. manager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue()) { [weak self] (data: CMAccelerometerData!, error: NSError!) in self!.outputAccData(data.acceleration) } But this gives me the following error. Type of expression is ambiguous without more context Does anyone know why this is happening?...

How do you save data that is being produced in a handler?

The handler code (in this case, collecting accelerometer data) is being executed asynchronously when my accelerometer moves. That means if I try to save data.x, data.y, data.z in a variable, even if the variable is declared outside of the handler, the variable will be nil if I attempt to print...

iOS9 error on activityManager.startActivityUpdatesToQueue

I opened my app in the new Xcode7 beta which worked perfectly fine in older version. Now I'm receiving errors, and i don't know how to solve it. Here is the code. Error is commented out. import UIKit import CoreMotion class ViewController: UIViewController { let activityManager = CMMotionActivityManager() let pedoMeter...

Rotation on Y axis in degree or radians in iOS

I need to get Rotation for iDevice on portrait mode, around Y axis of accelerometer, as per shown in this image, (reference: https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html) How can i get rotation performed around Y axis, either in positive or negative. I've implemented few codes from stackoverflow/Apple code, i get no difference in roll,...

Decreasing accelerometer's sensitivity

I am making a game which have a square that moves from left to right, and at first I was using applyForce to do so, but I didn't like the results because it was not sensitive enough. Then I changed to velocity: func motionSensorUpdate(currentTime: CFTimeInterval){ let square = childNodeWithName(ksquarename) as!...

Unknown Type Name 'CMStepCounter'

I'm trying to count the steps of user using CoreMotion, HealthKitand everything that is needed. At first I tried it with Swift (I'm not good with swift) and imported these two files: import HealthKit import CoreMotion And when I declared CMStepCounter it successfully declared it, means the type was found....

CMPedometer as property, Error code 103

I'm building a step manager class, and in my .m file, I've added CMPedometer as a property: @interface WDStepTrackerManager () @property (nonatomic, strong) CMPedometer *pedometer; @end I then instantiate it in my init method (I've also tried lazy instantiation -- no effect): - (instancetype)init { self = [super init]; if...

Is it possible to obtain gyroscope data updates when app is in the background

My app uses a Bluetooth accessories so I turn the corresponding background mode on. Is it possible to receiving CoreMotion gyroscope data continuously in the background? The scenario is to scan and hook up a BLE peripheral device when the app is in the background. And to detect phone rotation...