I can't work out how to use SwiftUI in a notification content extension. It always appears black for me when the extension runs.
Here's the code in my extension right now:
class NotificationViewController: UIViewController, UNNotificationContentExtension {
override func viewDidLoad() {
super.viewDidLoad()
let child = UIHostingController(rootView: TaskCell_Previews.previews)
addChild(child)
child.view.frame = view.frame
view.addSubview(child.view)
child.didMove(toParent: self)
NSLayoutConstraint.activate([
child.view.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1),
child.view.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 1),
child.view.centerXAnchor.constraint(equalTo: view.centerXAnchor),
child.view.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}
func didReceive(_ notification: UNNotification) {
}
}
In this case, I'm just putting `TaskCell_Previews` in to try to get it working. Whenever I tap on the notification, it just shows a blank view (which has a 1-1 aspect ratio as that's defined in my plist).
Thanks for any help/advice.