Marco Fucci
Marco Fucci

Reputation: 1854

How to detect if the user is holding the iPhone with his hand

I'm looking for a way to determine if the user is holding his iPhone with his hand in objective-c. The problem is that for some reasons, the multitouch layer in my iPhone game doesn't work as expected when the user puts his iPhone on something (table, chair, sofa etc.) and uses it only with one hand. It doesn't depend on the orientation.

Any help appreciated!

Thanks.

Upvotes: 1

Views: 1554

Answers (2)

Oliver
Oliver

Reputation: 23500

Use the CMMotionManager.

http://developer.apple.com/library/ios/#documentation/CoreMotion/Reference/CMMotionManager_Class/Reference/Reference.html

Just keep a track of the device "userAcceleration" changes and analyse it. If it does not change, you can guess it's on a non moving object. If it change, you can guess it's into the hands of the user. The problem is that may not be perfect and need some precise adjustments and debug to find the correct values you may test (idea : you should make some test to see what happens if the iPhone is on a non moving object into a moving one like a car, a bus, a train, ...).

But that should work.

Upvotes: 2

Duncan Babbage
Duncan Babbage

Reputation: 20177

Rather than trying to overlay a kludge, you need to work out what is wrong with the implementation of the multitouch layer that means that it is not correctly activated unless the device is being held in someone's hand. The device being held in the hand is almost certainly only a proxy for what the real difference is in conditions between when the layer is working and when it is not... you need to figure out what the real difference in conditions is.

For instance: perhaps you're only correctly registering the multi-touch movements if there is a stationary touch somewhere else in the layer—inadvertent touch from holding the device?

Upvotes: 2

Related Questions