Created
April 14, 2017 05:27
-
-
Save acalism/bad6d454a941e1a01351fd7715034223 to your computer and use it in GitHub Desktop.
observe all notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 监听窗口事件 | |
// 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