1

I have an iMessage Extension in swift that is in expanded presentationStlye when a user taps a button. Once this button is tapped, it should dismiss the view entirely or at least return to compact mode. I am not sure what is wrong. Here is didTransition being called from my button:

self.didTransition(to: MSMessagesAppPresentationStyle.compact)

and the action:

override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {

    guard presentationStyle == .expanded else { return }
    self.dismiss(animated: true) {

    }
}

But this is not working. Does anyone know what I am doing wrong?

user3255746
  • 1,377
  • 3
  • 12
  • 13

3 Answers3

1

Actually the right func to call is that one :

requestPresentationStyle(MSMessagesAppPresentationStyle)

You can call it like this in your MSMessageAppViewController :

self.requestPresentationStyle(.compact)

You don't need to override anything ;) Hope this will help you!

Note: have a look to the documentation here: https://developer.apple.com/reference/messages/msmessagesappviewcontroller

It will help you a lot!

RomOne
  • 2,065
  • 17
  • 29
0

These function will help to move from one transition state to another in MSMessagesViewController:-

requestPresentationStyle(.expanded)    
requestPresentationStyle(.compact)

Above method will invoke willTransition and didTransition:-

  override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {

//Here we can check the presentationStyle and move the Controller according to need . i.e

    let controller: UIViewController
    if presentationStyle == .compact {
        controller = instantiateCompactController()
    }
    else {
        controller = instantiateExpandController()
    }
    //and then Present Controller
    }

For More Information : https://developer.apple.com/videos/play/wwdc2016/224/

Shrawan
  • 7,128
  • 4
  • 29
  • 40
0

You can also use the dismiss() function to dismiss an expanded MSMessagesAppViewController entirely.

Note this isn't the same as dismiss(animated:) which dismisses a modally presented vc. Docs here.

LOP_Luke
  • 3,150
  • 3
  • 22
  • 25