Topic: iPhone Accelerometer Simulator
I started to develop for iPhone, and I faced a problem, what I think is not only mine.
I had no device to test on it, but I wanted to work with the accelerometer.
I was looking around on the web for any simulator, without any success.
Finally I decided to create my own simulator. In the end it contains a small app and a UIAccelerometer replacement class.
The ideea is pretty simple, I made a small http server what serves the x,y,z acceleration values. I admit I was lazy to write the whole http server so I used the "simple http server", what is the base of the simulator. You can download it from: http://culturedcode.com/cocoa. Thanks for it.
The replacement class connects to the http server and instead of the accelerometer, it receives the acceleration values from the server app.
After that it simulates the behaviour of the UIAccelerometer class.
Anyone interested in it, may download the simulator, and the small class with what you should replace the class from the SDK.
iPhoneAccelerometerSimulator.zip
iPhoneAccelerometerSimulator.dmg
The usage is pretty simple, mostly you have to replace the UIAccelerometer references with zUIAccelerometer.
Here is a code snipett, based on the AccelerometerGraph app from the SDK for better understanding. If you do exactly the same changes what I did, the simulator should work.
First you have to download the AccelerometerGraph from here
In AppDelegate.h make the following change:
...
#import "GraphView.h"
/*accelerometer simulator*/
#import "zUIAccelerometer.h"
/*accelerometer simulator*/
...In AppDelegate.m do the following changes:
...
@implementation AppDelegate
@synthesize window;
@synthesize graphView;
@synthesize toolbar;
/*accelerometer simulator*/
zUIAccelerometer *am;
/*accelerometer simulator*/
......
- (void)applicationDidFinishLaunching:(UIApplication*)application {
...
...
// Configure and start the accelerometer
/*accelerometer simulator*/
am = [zUIAccelerometer alloc];
[am setDelegate:self];
[am startFakeAccelerometer];
//[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)];
//[[UIAccelerometer sharedAccelerometer] setDelegate:self];
/*accelerometer simulator*/
......
// UIAccelerometerDelegate method, called when the device accelerates.
/*accelerometer simulator*/
//- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
- (void)accelerometer:(zUIAccelerometer *)accelerometer didAccelerate:(zUIAcceleration *)acceleration {
/*accelerometer simulator*/
...That's all. If you have any question don't hesitate.
Enjoy, and feel free to comment and any constructive suggestion is welcome.
Cheers,
Zotya