Getting Accelerometer Data

In HypnosisViewController.m, add the following implementation of the UIAccelerometer delegate method, accelerometer:didAccelerate:. This method will log accelerometer updates to the console. Notice that the types of the two parameters are different even though they look similar:

-​ ​(​v​o​i​d​)​a​c​c​e​l​e​r​o​m​e​t​e​r​:​(​U​I​A​c​c​e​l​e​r​o​m​e​t​e​r​ ​*​)​m​e​t​e​r​
 ​ ​ ​ ​ ​ ​ ​ ​d​i​d​A​c​c​e​l​e​r​a​t​e​:​(​U​I​A​c​c​e​l​e​r​a​t​i​o​n​ ​*​)​a​c​c​e​l​
{​
 ​ ​ ​ ​N​S​L​o​g​(​@​"​%​f​,​ ​%​f​,​ ​%​f​"​,​ ​[​a​c​c​e​l​ ​x​]​,​ ​[​a​c​c​e​l​ ​y​]​,​ ​[​a​c​c​e​l​ ​z​]​)​;​
}​

Build and run the application on your device. Watch the console as you rotate and shake the phone to get a feel for the data that the accelerometer ...

Get iOS Programming: The Big Nerd Ranch Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.