Orientation Changes in AIR 3.5

Apple has made a significant change in the application orientation APIs in the newly released iOS 6 SDK. Some of the auto-orientation callbacks have been completely deprecated in iOS 6 SDK. This means apps packaged with iOS 6 SDK and running on iOS 6 devices will not receive the deprecated callbacks. However the same apps running on iOS 5.1 or earlier will continue to receive the deprecated native callbacks. This change affects the screen orientation API’s in AIR too and support for the new callbacks have been added in AIR 3.5 beta release available here.

Prior to iOS 6 SDK, native orientation callbacks informed the application about the new orientation it was being rotated to. Hence, an application could decide whether it wanted to rotate to the new orientation or not at runtime. However, the new callbacks do not give us such information.The OS only queries the application about the set of orientations it currently supports. If the new orientation that the application is being rotated to is one of these values, the application rotates automatically. Otherwise it does not.

How does this affect the orientation behavior and API’s in AIR?

As a result of this limitation of the new callbacks, support from preventDefault() is being deprecated on iOS. The application will still receive the ORIENTATION_CHANGING event. But calling preventDefault() inside the ORIENTATION_CHANGING event handler won’t prevent the stage from being rotated to the new orientation. It is important to note that apps packaged with iOS 6 and running on iOS 5.1 devices or lower will also see this behavior change of not able to control auto orientation by using preventDefault(). This was done to make this change consistent across iOS devices. It is suggested to switch Stage.autoOrients to false as and when auto orientation is to be prevented. 

11 Responses to Orientation Changes in AIR 3.5

  1. Dennis says:

    Well this sounds interesting. How do i make one app with landscape only in iPad and Portrait only in iPhone? Its a pretty basic setup – that now seems impossible to implement.

    • Varun Bhatia says:

      Just wanted to know how did you address the use case earlier? But as a workaround, you can check for iPad device at launch time and then set aspect ratio to landscape or the other way round for iPhone.

  2. Dennis says:

    I just listened for the StageOrientationEvent

    and then did this:
    if (deviceType == “iPad”) {
    traceTF(“device type = iPad”);
    if (e.afterOrientation == StageOrientation.ROTATED_RIGHT || e.afterOrientation == StageOrientation.ROTATED_LEFT) {
    e.preventDefault();
    traceTF(“prevent change”);
    }
    }else {
    traceTF(“device type = iPhone”);
    if (e.afterOrientation == StageOrientation.DEFAULT || e.afterOrientation == StageOrientation.UPSIDE_DOWN) {
    e.preventDefault();
    traceTF(“prevent change”);
    }
    }

    If i understand you correctly you just want me to disable autoOrienting and then just setting the orientation when the app has launched. Sounds so obvious – will try it out asap.

    • Elwin says:

      I had the same problem.
      Apparently that workaround is not necessary anymore since 3.3, see http://blogs.adobe.com/airodynamics/2012/05/22/stage-aspectratio-enhancements/.

      If you set “autoOrients” to true and put the following code in an AddedToStage handler then you’re set:

      if (deviceType == “iPad”) {
      stage.setAspectRatio(StageAspectRatio.LANDSCAPE);
      } else {
      stage.setAspectRatio(StageAspectRatio.PORTRAIT);
      }

      You don’t need to do a preventDefault anymore so it still works in iOS 6.

  3. Pingback: Orientation Changes in AIR 3.5 | TechnoVeille

  4. Thenrion says:

    What if we need to handle Landscape and Landscape-Left orientation changes?

    • Varun Bhatia says:

      You always receive an Orientation_Changing event. Howver you cant prevent this orientation change.

  5. Colin Holgate says:

    An app I made with AIR 2.0 uses preventdefault() to make sure the app can only rotate to landscape, and not to portrait. It uses the changing event to do that. It continues to work in iOS 6. Why does it still work if you say that it shouldn’t?

    • Varun Bhatia says:

      Any native app(or and AIR app too) packaged with iOS 5.1 or earlier still receives the deprecated callbacks and hence its possible to prevent orientation being changed! AIR 2.6 was build using iOS 4.2 as far as I remember and hence apps packaged with previous sdks remain unaffected.

  6. Hi People,

    This is interesting. I am creating an app that is going to be presented in landscape.

    However if the phone is rotated, I want to rotate a single graphic and leave the rest of the app in the landscape orientation.

    So I do not want to rotate the stage – just react to the change in phone orientation.

    Am I looking at the wrong functionality ( the auto orientation functionality ) for this?

    Thanks

    Steve

    • Varun Bhatia says:

      I understand the use case. It could have been easily implemented using the stage auto orientation before the changes mentioned above. You can probably use accelerometer and device orientation values for such use case.