Today widget in iOS 10 is not expanding
Asked Answered
C

1

7

I'm trying to solve an issue with my today widget. It's not expanding on iOS10 after pressing "Show more" button. It's size keeps the same all the time.

Here is the code for TodayViewController.swift

import UIKit
import NotificationCenter

class TodayViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        extensionContext?.widgetLargestAvailableDisplayMode = .expanded
    }
}

extension TodayViewController: NCWidgetProviding {

    func widgetActiveDisplayModeDidChange(activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
        if activeDisplayMode == .expanded {
            preferredContentSize = CGSize(width: 0, height: 280)
        } else {
            preferredContentSize = maxSize
        }
    }
}

Any hints please?

Celina answered 25/1, 2017 at 17:34 Comment(0)
P
12

Assuming that you are coding using Swift 3 (or later), please note that

widgetActiveDisplayModeDidChange method signature is:

optional func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize)

So, it should be:

func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
    if activeDisplayMode == .expanded {
        preferredContentSize = CGSize(width: 0, height: 280)
    } else {
        preferredContentSize = maxSize
    }
}

You could also add a breakpoint to your current method and check whether it's reachable or not.

Painter answered 25/1, 2017 at 17:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.