iMessageApp - MessagesViewController is not in the view hierarchy

104 Views Asked by At

I work on the iMessage App and stumbled upon this nasty bug. I would really appreciate the power of the community. Did anyone manage to solve it?

  • A clear description of the problem:

I work on a Standalone iMessage App. When the iMessage app is active but hidden below the keyboard tapping on the message from that extension opens an app with an empty screen. Investigation of this problem led me to the conclusion that there is no UIWindow attached to the window property of the view in the MessagesViewController. Also, the MessagesViewController is not displayed in the view hierarchy, and MessagesViewController life cycle methods like viewDidLoad and viewDidAppear are not called.

  • A step-by-step set of instructions to reproduce the problem:
  1. Open an iMessage App (for example Youtube) and send a message from that app to a chat.
  2. Open the iMessage App again
  3. Scroll up so that the iMessage App gets hidden below the keyboard
  4. Scroll down to find a message that you’ve sent in step 1
  5. Tap on the message
  6. The app will expand with an empty view

Here is the bug reproduced in Apple's iMessage Example App https://youtube.com/shorts/3UGyZimctSg?feature=share

1

There are 1 best solutions below

0
jecls On

I also came across this bug and can reproduce the issue in Apple's sample app as well as every iMessage app on the app store I've tested, except for GamePigeon.

The issue is that the MSMessagesAppViewController's view is not part of any UIWindow hierarchy when you try to reopen the app, but it still has it's parent property. So I came up with this workaround:

override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
    super.didTransition(to: presentationStyle)
    if self.view.window == nil {
        if let parent = self.parent {
            self.view.frame = parent.view.bounds
            parent.view.addSubview(self.view)
        }
    }
}

Since the ViewController has no window, it doesn't get standard life cycle events like you said, but didTransition(to presentationStyle: MSMessagesAppPresentationStyle) still gets called so that's where I've put this.