1

Is there a way to prevent the user from dismissing a modal controller?

I think it is pretty common to want to "block" the main Watch App interface while asking the user to open the iPhone counterpart or to perform some action there.

My current solution is to present again the controller when it gets dismissed but its clunky.

Rivera
  • 10,792
  • 3
  • 58
  • 102

3 Answers3

2

There's a somewhat kludgy way to get around this issue using reloadRootControllers. When you call reloadRootControllers(withNamesAndContexts:) with the name of a WKInterfaceController that you've named in your storyboard, it has a similar effect to presenting that controller modally. However, since it's now the root controller, it doesn't have a cancel button. I don't really like this, but it does get the job done.

Note this method is deprecated since watchOS 4. Apple Documentation on reloadRootControllers(withNamesAndContexts:)

Hackman
  • 2,629
  • 3
  • 18
  • 24
Ben Lachman
  • 3,083
  • 1
  • 28
  • 44
  • 1
    I think this could be a valid way avoiding modals all together. Unless one needs animation and actual modal functionality they probably don't want a modal to begin with. I'd add, it's a good way to migrate to another set of "pages" by having them connected in the storyboard and passing the identifiers in the names array. (Thanks Ben) – migs647 Oct 16 '18 at 01:13
1

The trick is to make the modal screen fullscreen and change the inset top value for your main group.

enter image description here Preview of modal view

Hackman
  • 2,629
  • 3
  • 18
  • 24
0

You can't prevent a modal interface controller from being dismissed, as the system automatically dismisses it when the title is tapped.

Since your code isn't asked if it should happen, but only knows that it is happening, there's no way to intercept or cancel that action. The WKInterfaceController documentation briefly touches on this.

When the user taps the title string, WatchKit automatically dismisses the modal interface without taking any further actions.

What can you do?

While you don't know when the Cancel title is tapped, there is a hack which "hides" the Cancel title.

This may confuse users who might wonder how to dismiss the modal, or mislead others into thinking the modal couldn't be dismissed.

What does the HIG recommend?

Circumventing a Human Interface Guideline would likely degrade the entire user experience.

The top-left corner of the modal sheet is reserved for the Close button, which dismisses the interface.

Some users might be frustrated or annoyed if

  • there is no apparent way to cancel, or

  • the modal presents itself again after repeatedly being cancelled.

Since the user expects to be able to dismiss the modal, perhaps you could allow them to do just that, then simply display some form of reminder in the presenting interface controller (to log in, or enable permissions).

Community
  • 1
  • 1
  • What I find very annoying is that Apple flaunts their own Guidelines in several of the built-in apps: * In the `Alarm` app, `Add Alarm` pushes to a "full screen" interface w/ a `Cancel` button on the bottom left instead of the title bar (which is entirely hidden). * The `Messages` app does something similar in `New Message` menu, which opens a modal where the title bar is not clickable, and instead a `Cancel` button is on the bottom left. But, as far as I can find, there's no way for my app to have the same behavior. – Ryan Jul 28 '17 at 20:58
  • In my case the app records data from the sensors, and it's absolutely important to know when the user taps the back button, for the app needs to stop the recording. Otherwise if the user navigates several times to the controller back and forth, it could happen that there are several recorders allocated that can't be stopped. This could cause the app to draw all of its memory. – Ramy Al Zuhouri Nov 02 '17 at 21:03