zakdances
zakdances

Reputation: 23695

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");
}

Upvotes: 0

Views: 501

Answers (3)

zakdances
zakdances

Reputation: 23695

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

Upvotes: 1

Bajaj
Bajaj

Reputation: 869

end of the bool type something set the orientation .write return yes in all end of the view ..orientation in potrait and landscape mode takeplace

Upvotes: 0

J2theC
J2theC

Reputation: 4452

You need to use the Orientation notification, which is UIDeviceOrientationDidChangeNotification. Do not put it inside the @"UIDeviceOrientationDidChangeNotification" because you dont know the actual content of the constant which is UIDeviceOrientationDidChangeNotification. It appears you are using a view controller. You should use willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation:

Upvotes: 0

Related Questions