Supporting Documentation for Using Accelerometer in iOS Simulator

As everyone is probably aware, the iOS Simulator doesn’t provide any mechanism to simulate the Accelerometer available on actual devices. If you’re using a Macbook, these devices have a freefall sensor in them that can be used to simulate an accelerometer. Whilst it’s not exactly ideal, it can be useful if you wish to test your code easily without having to go through all of the certificate rigmarole.

NB: The details as to how I’ve done this is described below but I am in no way affiliated to the Open Source projects from which I gathered the code. Obviously, use at your own risk. :slight_smile:

This documentation relates to the pull request I’ve issued to have these features integrated into the next release of Cocos2D-x.

What you need:

  1. You need the code in the aforementioned link above. This utilises the code from: http://code.google.com/p/accelerometer-simulator/wiki/Home and integrates it within Cocos2D-x.

  2. You need to download and build the Unimotion code from: https://github.com/gmarik/unimotion

  3. You need to open up a Terminal window and run the Unimotion binary you created at step 2. Refer to the Unimotion documentation for details on this.

  4. You need to add a line to your main.m file:

    #import “cocos2dx/platform/ios/Simulation/AccelerometerSimulation.h”

  5. You now need to build and then run your App for the iOS Simulator.

You don’t need to do anything else. If Unimotion is running, your App will receive accelerometer updates as you pick up and wiggle your Macbook.

Naturally, you will still need to test and address the functionality of your App with actual devices but at least you can do some rudimentary testing with your code.

Roc

Note that some MacBook Airs don’t have an accelerometer. I prefer to use iSimulate instead. You simply link their library and run their app on your iPhone. Any movement & touches on the iPhone are mirrored in the simulator.

I have problem to use Unimotion

$ src/bin/motion -f 17 | python sendaccsim.py
Could not detect an SMS

Why I get this message?

I use iMac and osx 10.7.3

I think it’s because you’re using an iMac - these machines don’t have a Motion Sensor like MacBooks, although, note the comment above about some of the skinny MacBook Airs.