Search code examples
iphoneobjective-ciosnotificationsnsnotificationcenter

No orientation-related notifications are being fired. Why?


I want to be notified when the orientation of the device changes. I've setup a test method that's suppose to receive the notification. I'm trying several different observers to achieve that, and none of them are working. Why isn't testMethod being fired?

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    // register for orientation change notification

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(testMethod)     name:@"UIDeviceOrientationDidChangeNotification" object:nil];

    [[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(testMethod)
                                             name: UIApplicationWillChangeStatusBarOrientationNotification
                                           object: nil];
    [[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(testMethod)
                                             name: UIApplicationDidChangeStatusBarOrientationNotification
                                           object: nil];
}

- (void)testMethod
{
    NSLog(@"phone was rotated");
}

Solution

  • I accidentally had the rotation lock engaged on my phone. Always test on more than one phone!