2017-05-30 45 views

回答

2

你的框架可以作爲.UIApplicationSignificantTimeChange觀察者寄存器,而不是依賴於UIApplicationDelegate方法:

class MyClass { 
    var observer: NSObjectProtocol! 

    init() { 
     observer = NotificationCenter.default.addObserver(forName: .UIApplicationSignificantTimeChange, object: nil, queue: .main) { [weak self] notification in 
      self?.handleNotification(notification) 
     } 
    } 

    private func handleNotification(_ notification: Notification) { 
     // do something 
    } 

    deinit { 
     NotificationCenter.default.removeObserver(observer) 
    } 
} 
相關問題