0

Using the CMAttitude* information from an iPhone you can tell the pitch. It the iPhone is vertical it's 90º. If it's flat it's 0º. But I have an app that need to know if the iPhone is facing up or down/forwards or backwards. Any idea if this can be done?

>     * CMAttitude *attitude;
>       CMDeviceMotion *motion = motionManager.deviceMotion;
>       attitude = motion.attitude;
Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
Edward Hasted
  • 3,201
  • 8
  • 30
  • 48

1 Answers1

1

Have you tried checking device orientation by using UIDevice class?

Edited: First add an observer to monitor orientation change:

- (void)viewDidLoad
{
    [super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationDidChange:)
                                                 name:UIDeviceOrientationDidChangeNotification object:nil];
}

In the callback, obtain current device orientation

 - (void)orientationDidChange:(NSNotification*)notification
 {
     /// check current orientation
     switch ([[UIDevice currentDevice] orientation])
     {
         case UIDeviceOrientationPortrait:
             break;
         case UIDeviceOrientationPortraitUpsideDown:
             break;
         case UIDeviceOrientationLandscapeLeft:
             break;
         case UIDeviceOrientationLandscapeRight:
             break;
         case UIDeviceOrientationFaceUp:
             break;
         case UIDeviceOrientationFaceDown:
             break;
         default: /// UIDeviceOrientationUnknown
             break;
     }
 }

This will notify you whenever the device changes it's orientation.

Supported orientations can be found here: https://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html

Casey
  • 103
  • 6
Casey
  • 26
  • 1
  • Perfect, this call alerts you when there is change but not of the current status. I suspect I can presume the iPhone will be face up and then can correct is else if it gets moved. Many thanks. – Edward Hasted Aug 15 '14 at 06:53