I have an extension I've taken down the bare bones, which is putting itself in incorrect states, where it'll say "Show Less" when it's collapsed.
This is happening in two circumstances
- I expand the extension with "Show More" and then leave the screen. I open up another app, and then return to the extension. The expanded extension visibly collapses in front of me, but still says "Show Less"
- I push a new build to test changes. It will be expanded from before, and when the new build pushes it becomes collapsed and says "show less"
I also tried having another extension active (weather) with it expanded, and it always remains expanded once expanded, while my extension is collapsing and showing the wrong state.
This happens with and without the weather widget present.
When I put break points in the code, in step #1 ViewDidLoad is being called again.
Here's the code, I deleted everything bit by bit until this was all that was left and still causing the problem.
class TodayController: UICollectionViewController, NCWidgetProviding {
let reuseIdentifier = "TimeGridCell"
override func viewDidLoad() {
super.viewDidLoad()
self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(_ collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return 3
}
override func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,
for: indexPath) as! ArtistTimeGridTableViewCell
cell.nameLabel.text = "blah blah"
return cell
}
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if activeDisplayMode == .expanded {
self.preferredContentSize = (self.collectionView?.contentSize)!
} else if activeDisplayMode == .compact {
self.preferredContentSize = maxSize
}
}
}
Note that if I remove self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded then I don't get the option to expand or collapse at all, so it's required.
Here's images of the problem. First image is correct, second one is incorrect.

