To use the accelerometer in the simulator, we need:
Mac with a built-in accelerometer (MacBook, MacBook Pro, MacBook Air), the readings of which will be transmitted to the simulator
Unimotion - a program that removes readings from an accelerometer built into Mac
Accelerometer Simulator - an application that sends readings from a real iPhone accelerometer to a Mac. (It consists of 2 parts: an application installed on the iPhone; and a class that connects to the application under test.)
The sendaccsim.py script that converts readings from Unimotion for use in the Accelerometer Simulator:
while 1: try : line = sys.stdin.readline()[:-1] # read line and strip EOL fields = line.split() # split around space character floatfields = map(float , fields) # convert to floats # transform coordinate system, from Sudden Motion Sensor to UIAcceleration format x, y, z = map( lambda x: -1 * x, floatfields)
# change epoch to be compatible with CFAbsoluteTimeGetCurrent() currentTime = time.time() - kCFAbsoluteTimeIntervalSince1970
First you need to build Unimotion. C sourceforge.net download and unpack the archive with the program. Go to the unpacked folder and execute make , after which we have a bin folder containing motion and libUniMotion.dylib . There we copy sendaccsim.py and run it: $ ./motion -f 17 | python sendaccsim.py
From Accelerometer Simulator we take AccelerometerSimulation.h and AccelerometerSimulation.m and connect to our project in AppDelegate.h :
#import "AccelerometerSimulation.h"
')
Run the application in the simulator, and emulate the accelerometer iPhone, tilting the Mac left-right :).
For example, you can take the game Tweejump and play it directly on the Mac. It was found in the open spaces of GitHub and was chosen only because it uses an accelerometer to control the player.