I'm writing a Today Extension, and it's working correctly on my iOS 9 device.
On iOS 10, I've read numerous posts saying we need to set expanded mode for the extension to expand further than the 110 height, but when I follow all the answers out there on how to do this, my widget continually stays in compact mode.
This is what I'm using
@available(iOS 10.0, *)
@available(iOSApplicationExtension 10.0, *)
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if activeDisplayMode == .expanded {
self.preferredContentSize = CGSize(width: maxSize.width, height: 400)
} else if activeDisplayMode == .compact {
self.preferredContentSize = CGSize(width: maxSize.width, height: 110)
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 10.0, *) {
self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded
}
}
I set the value to expanded, and then it goes into the protocol, and while in there, it goes into the else statement for compact, instead of expanded.
I've tried setting the mode in viewDidAppear as well as viewWillAppear.
Nowhere else in my code am I'm setting the preferedContentSize
There's a dozen answers out there saying that this should work, for the life of me I can't figure out what I've done wrong?
Is there something else I need to be doing?
This is an example of an accepted answer for this - Today Extension: How to work with display mode?
UPDATE: I just saw the "Show More" button... maybe I was misunderstanding things, is it possible to have this start expanded? Am I forced to press the Show More button? That might explain why it's not working?
What you're doing when you implement widgetActiveDisplayModeDidChange
is permitting the user to expand the widget. The Show More text appears at the top right, and the user can tap this to switch to expanded mode. Apple's Weather app widget is a standard example.