iosuideviceorientation

iOS App Does Not Detect Device Orientation Change


I have an issue with orientation change in my app. My app supports Portrait, LandscapeLeft and LandscapeRight Device Orientations, which I am 100% sure that I configure it properly in the Info.plist. When I run my app on my iPhone/Simulator, and rotate the device, none of my app ViewControllers responses to the rotation. That is, no ViewControllers can be changed to Landscape Mode regardless of how hard and crazy I rotate my phone. I tried to override the 'Autorotate' var to return true/false, same result, My app stick to single Portrait Mode, which is not what I want. So I was thinking maybe my app couldn't even detect the Device Orientation Change; therefore, I put the following code in my AppDelegate, and I was right, func "deviceOrientationDidChange" is never called when I rotate my phone, but it's called when app enter background. Anyone has any clues? I have been struggling with this for days, and trying to find a solution from internet, but no hope. Please help.

UIDevice.current.beginGeneratingDeviceOrientationNotifications()
let notifiCenter = NotificationCenter.default
notifiCenter.addObserver(self, selector: #selector(self.deviceOrientationDidChange(_:)), name: .UIDeviceOrientationDidChange, object: nil)

func deviceOrientationDidChange(_ notification: Notification) {
    print("device orientation did change...")
}

Solution

  • I still couldn't figure out what the causes really are, but this issue did get fixed after I Pod Update all the pod frameworks used in my app. I really tried so hard to try to find out what causes this issue. Unfortunately, I couldn't. I have about 20 3rd-party frameworks installed via pod. My fix to this issue is Pod Update. No luck on what the causes are. Hope this answer will help someone in the future.