title: iOS app force landscape on tablets, force portrait on phones with same build
body: <p>I have a Swift iOS app which runs on all phones and tablets.
  I want to use the same codebase and IPA file for all devices.
  On phones the app should be portait.
  On tablets the app should be landscape.</p>
  
  <p>I can get it to not allow rotation if you are in the correct orientation, but if you launch the app when the device is in the wrong orientation, it will start off the app in the wrong orientation and force you to physically rotate the phone to fix it, and even then the screen is messed up.</p>
  
  <p>In the General:Deployment Info:Device Orientation: I have both Portrait and Landscape checked</p>
  
  <p>note this is similar to other questions already asked but I can't find my special situation.</p>
  
  <p>I am using this code in all View Controllers to prevent rotation if you are already in the correct orientation:</p>
  
  <pre><code>    override func shouldAutorotate() -&gt; Bool
  {
      let orientation:UIDeviceOrientation = UIDevice.currentDevice().orientation
  
      print(orientation)
  
      if(UIDevice.currentDevice().userInterfaceIdiom == .Phone)
      {
          if(orientation.isLandscape)
          {
              return true
          }
      }
      else
      {
          if(orientation.isPortrait)
          {
              return true
          }
  
      }
  
      return false
  }
  
  override func supportedInterfaceOrientations() -&gt; UIInterfaceOrientationMask
  {
      if(UIDevice.currentDevice().userInterfaceIdiom == .Phone)
      {
          return UIInterfaceOrientationMask.Portrait
      }
      else
      {
          return UIInterfaceOrientationMask.Landscape
      }
  }
  </code></pre>