Skip to content

Instantly share code, notes, and snippets.

@acalism
Created April 14, 2017 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acalism/bad6d454a941e1a01351fd7715034223 to your computer and use it in GitHub Desktop.
Save acalism/bad6d454a941e1a01351fd7715034223 to your computer and use it in GitHub Desktop.
observe all notification
// 监听窗口事件
// NSNotification.Name.UIWindowDidBecomeHidden = "UIWindowDidBecomeHiddenNotification"
NotificationCenter.default.addObserver(forName: NSNotification.Name.UIWindowDidResignKey, object: nil, queue: .main) { (notice) in
guard let w = notice.object as? UIWindow else { return }
if w == self.window {
lockDeviceInterfaceToLandscape = true
app.statusBarOrientation = .landscapeRight
} else {
lockDeviceInterfaceToLandscape = false
app.statusBarOrientation = .portrait
print(w)
}
}
// 为webView播放视频监听通知 for UIWebView, 在 iOS 7 及更早有效
// "UIMoviePlayerControllerDidEnterFullscreenNotification", "UIMoviePlayerControllerDidExitFullscreenNotification"
// "AVPlayerItemBecameCurrentNotification" "AVPlayerItemNewAccessLogEntry" 也失效了
// 监听所有通知
NotificationCenter.default.addObserver(forName: nil, object: nil, queue: nil) { (notice) in
if let obj = notice.object {
print(obj)
}
print("【all Notification】\(notice.name), \(notice.userInfo ?? [:])")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment