I don\'t have an iPhone 4 with me right now and I am trying to find a documentation that shows the ranges of yaw, pitch and roll and the correspondent positions of the devic
I have recently faced the same problem for an iOS app that counts the number of flips that the phone does. Apple has rejected it so I have published it on GitHub, may be useful for you:
Flip Your Phone! - https://github.com/apascual/flip-your-phone
I never thought on the solution using the gravity Z variable, I will try it soon and I come back with some updates.