Question

I am developing application to get threshold how forcefully user shook iOS device. I am using iOS sdk 6.0.

I tried UIResponder delegate method motionEnded:: It get called when device is shaken but do not give enough data that how forcefully some one shook device. I searched enough and found a single solution to use UIAccelerometer didAccelerate call back method. But it is not getting called. Is it sdk issue? As this method is deprecated in iOS 5.

I also tried coreMotion framework but that gives gyroscope data that how much device have been rotated but not how much it is has been shaken. What is the best way of doing this. I followed How do I detect when someone shakes an iPhone? but found no useful answer.

Was it helpful?

Solution

I just figured it out. iOS simulator do not respond to UIAccelerometer actions even if you perform shake gesture or rotate the simulator. It will not work. But if you run on device you will find same piece of code is running fine :)

OTHER TIPS

Try this, in your view did load just do this:

UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;

This made it work for me. Dont need to use the variable at all, but it has something to do with setting the shared accelerometers delegate to self

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top