【发布时间】:2016-08-01 10:59:16
【问题描述】:
在有用的问题Force reload watchOS 2 Complications 用户@alexeyvmp 提到in a comment,您应该为CLKComplicationServerActiveComplicationsDidChangeNotification 事件添加观察者。
创建这个观察者的好地方是什么,它会是什么样子?我是从我的 ComplicationDataSource 还是在我的 InterfaceController 中创建它?如何确保它不会一遍又一遍地重新创建?
我试图在Swift 中阅读有关如何创建观察者的信息,但我很难弄清楚将其放在哪里。我目前有
let notificationCenter = NSNotificationCenter.defaultCenter()
let mainQueue = NSOperationQueue.mainQueue()
_ = notificationCenter.addObserverForName(CLKComplicationServerActiveComplicationsDidChangeNotification, object: nil, queue: mainQueue) { _ in
print("active complications changed. refresh!")
}
感谢任何帮助。
【问题讨论】:
标签: swift apple-watch nsnotificationcenter apple-watch-complication clockkit