1

On the helpful question Force reload watchOS 2 Complications user @alexeyvmp mentions in a comment that you should add an observer for the CLKComplicationServerActiveComplicationsDidChangeNotification event.

What is a good place to create this observer, and what would it look like? Do I create it from my ComplicationDataSource, or in my InterfaceController? How do I make sure it's not recreated over and over?

I have tried to read up on how to create observers in Swift but I'm having a hard time figuring out where to put it. I currently have

let notificationCenter = NSNotificationCenter.defaultCenter()
let mainQueue = NSOperationQueue.mainQueue()

_ = notificationCenter.addObserverForName(CLKComplicationServerActiveComplicationsDidChangeNotification, object: nil, queue: mainQueue) { _ in
    print("active complications changed. refresh!")
}

Any help is appreciated.

Community
  • 1
  • 1
oelna
  • 2,210
  • 3
  • 22
  • 40

1 Answers1

1

You should place the observer in InterfaceController:

NotificationCenter.default.addObserver( self,
        selector: #selector(InterfaceController.CLKComplicationServerActiveComplicationsDidChangeNotification(_:)),
        name: NSNotification.Name(rawValue: "CLKComplicationServerActiveComplicationsDidChangeNotification"), object: nil )

So you will know in InterfaceController when the complication changed.

Cosmin
  • 6,623
  • 3
  • 26
  • 28