MSMessagesAppViewController orientation lock

I want my subclass of MSMessagesAppViewController to be portrait-only, is there a way to lock the orientation?


My plist contains

<key>UISupportedInterfaceOrientations</key>
  <array>
  <string>UIInterfaceOrientationPortrait</string>
  </array>


And I tried overriding

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .portrait
}


But I am still able to rotate the device and see my layout in landscape. I suppose this is related to the fact that iMessage apps are extensions, is that right? Is there a way?

Accepted Reply

Yes, it's a requirement to support both landscape and portrait - I asked this a month ago and Apple support replied that we must follow the constraints and behaviors of iMesage.


Make sure that you put everything in a scrollview that scroll properly based on orientation - reason for scrollview so that it will support anything that might be off screen in smaller device visible area in different orientations.

Replies

I believe since you live inside the iMessage app as an extension, you are in their rules. That's why you can have an App that also has a Message extension. Another reason why when you click on one of your messages you go expanded (instead of compact - someone brought this up and might have submitted a radar request). Apple probably wants a consistent usage inside of iMessage, since you can always send a normal text message.


FWIW, I'm writing my apps to support landscape/portrait for iMessage as iMessage can be in either orientation when it brings up your app.

Yes, it's a requirement to support both landscape and portrait - I asked this a month ago and Apple support replied that we must follow the constraints and behaviors of iMesage.


Make sure that you put everything in a scrollview that scroll properly based on orientation - reason for scrollview so that it will support anything that might be off screen in smaller device visible area in different orientations.

Thanks for mentioning this is an Apple requirement. If anybody comes up with a workaround, please post it here for future reference.

Does anyone knows how to detect rotation in MSMessagesAppViewController

I have override viewWillTransition, but it will always give me orientation unknown from UIDevice.current.orientation

Does anyone knows how to detect rotation in iMessage extension and update screen based on the rotation

I use the solution presented in this thread: https://forums.developer.apple.com/thread/53754

It seems it's one rule for us and a different one for Apple then, as the iMessage app store seems to support portrait only. If anyone has any ideas how to achieve this without private APIs please let us know! 🙂