IOS8 + UIDeviceOrientationDidChangeNotification does not receive a call

In my working application (iOS 7.0.1) is called UIDeviceOrientationDidChangeNotification.

Now when I run this application in iOS 8.0, it UIDeviceOrientationDidChangeNotificationdoes not receive the call.

I tried a lot, but no luck.

EDIT-1:

I have the code below to add an observer to change orientation. Works fine in iOS 7. No luck for iOS 8.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
+4
source share
3 answers

In my case, after many searches, I found that I made a silly mistake that my lock with restrictions on access to the device is turned on.

Please confirm the device orientation lock in the settings.

-.

+8
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didRotateDeviceChangeNotification:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];
< →
-(void)didRotateDeviceChangeNotification:(NSNotification *)notification
{
    UIInterfaceOrientation newOrientation =  [UIApplication sharedApplication].statusBarOrientation;
    if ((newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight))
    {

    }
}
+3

Swift 3:

Add observer in UIDeviceOrientationDidChange in viewDidLoad

        NotificationCenter.default.addObserver(self, selector: #selector(orientationChanged), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)

The selection method is as follows:

    func orientationChanged(notification: Notification) {

    }

Do not forget to add Remove observer using deinit method

NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
+1
source

All Articles