iOS8 + UIDeviceOrientationDidChangeNotification not getting called
Asked Answered
A

3

7

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

Now when i run this application in iOS 8.0 UIDeviceOrientationDidChangeNotification is not getting called.

Tried a lot but no luck.

EDIT-1:

I have use below code to add observer for orientation change. Works perfect in iOS 7. No luck for iOS 8.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
Arithmetic answered 30/9, 2014 at 6:54 Comment(8)
Without changing anything in my previous code it got working in iOS 8.0. Adding Observer and soonDecimate
@Decimate I did the same.Arithmetic
I have posted my code . Please have a look. Its working in iOS 8.0Decimate
@Decimate I got it, It is issue from the third party library which i have used. Thanks for helpArithmetic
@Decimate I still face an issue, edited my question.Arithmetic
I have not used this library in any of my project. Will check it.Decimate
I figure it out, These rotation methods are deprecated in iOS 8.0. Checked UIViewController.h class.Arithmetic
What ended up being the solution here? It's very unclear to me, and I'm still having this issue. None of the documentation for UIViewController.h is helpful. I'm registering for the UIDeviceOrientationDidChangeNotification event but it never happens, so the method for the selector I'm passing in never gets called (works with iOS 7 SDK, but not iOS 8 SDK)Plasmasol
C
15

In my case, after lot of searches I found that I'd made a silly mistake, that my device potrait orientation lock is on.

Please confirm the device orientation lock off in the settings.

This may help someone.

Childe answered 27/8, 2016 at 6:23 Comment(0)
D
3
[[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))
    {

    }
}
Decimate answered 30/9, 2014 at 7:40 Comment(2)
I figure it out, These rotation methods are deprecated in iOS 8.0. Checked UIViewController.h class.Arithmetic
@Kampai, I don't think the notification of the device orientation is deprecated yet.Novelist
W
2

Swift 3:

Add observer to UIDeviceOrientationDidChange in viewDidLoad

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

Selector method is like this:

    func orientationChanged(notification: Notification) {

    }

Don't forget to add Remove observer on deinit method

NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
Wurth answered 6/6, 2017 at 6:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.