Managing Device Orientation

IDWise SDK only supports portrait orientation for its screens.

You can either lock your entire app to portrait mode or use the provided helper class to lock orientation for the IDWise SDK screens only, while allowing other orientations elsewhere in your app


Option 1: Locking the entire app to Portrait orientation

You can configure your app from Xcode configuration to always be in portrait mode. We can do that in our target's Deployment Info section.


Option 2: Locking IDWise SDK screens only to Portrait orientation

  1. Add the following struct to your code
struct AppUtility {

    static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
    
        if let delegate = UIApplication.shared.delegate as? AppDelegate {
            delegate.orientationLock = orientation
        }
    }

    /// OPTIONAL Added method to adjust lock and rotate to the desired orientation
    static func lockOrientation(_ orientation: UIInterfaceOrientationMask, andRotateTo rotateOrientation:UIInterfaceOrientation) {
   
        self.lockOrientation(orientation)
    
        UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
        UINavigationController.attemptRotationToDeviceOrientation()
    }

}
  1. Update your AppDelegate.swift class

In your AppDelegate.swift, add the following code to manage the supported orientations:

// Set the default orientations allowed for your app
var orientationLock = UIInterfaceOrientationMask.all

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
  return self.orientationLock
} 
  1. Lock the orientation before starting the IDWise journey

Before initializing and starting the IDWise journey, lock the orientation to portrait using this code:

AppUtility.lockOrientation(.portrait)
  1. Unlock orientation after the IDWise journey is completed

Once the IDWise journey is finished or cancelled, unlock the orientation to allow other orientations in your app again:

AppUtility.lockOrientation(.all)

This ensures that only the IDWise SDK screens are restricted to portrait mode, while the rest of your app can maintain its default orientation settings.