【问题标题】:How can I change this deprecated code ? (flutter_inappwebview)如何更改此已弃用的代码? (flutter_inappwebview)
【发布时间】:2021-02-14 03:49:12
【问题描述】:
我的代码使用了 inappview 依赖项,但会引发此警告:
“statusBarStyle”的设置器在 iOS 9.0 中已弃用:使用 -[UIViewController preferredStatusBarStyle]
如何将此弃用的代码转换为新版本的代码?
public func hide() {
isHidden = true
// Run later to avoid the "took a long time" log message.
DispatchQueue.main.async(execute: {() -> Void in
self.presentingViewController?.dismiss(animated: true, completion: {() -> Void in
self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0)
UIApplication.shared.delegate?.window??.makeKeyAndVisible()
if self.previousStatusBarStyle != -1 {
UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: self.previousStatusBarStyle)!
}
})
})
}
【问题讨论】:
标签:
ios
swift
xcode
flutter
flutter-inappwebview
【解决方案1】:
在视图控制器中重写preferredStatusBarStyle 方法,并调用setNeedsStatusBarAppearanceUpdate 方法来更新状态栏的外观。您还可以将 previousStatusBarStyle 属性设为可选,以便您可以使用 if-let 检查其可用性。如果要隐藏状态栏,则覆盖 prefersStatusBarHidden 方法以返回 true。
class YourViewController : UIViewController {
var previousStatusBarStyle: UIStatusBarStyle?
public func hide() {
isHidden = true
// Run later to avoid the "took a long time" log message.
DispatchQueue.main.async(execute: {() -> Void in
self.presentingViewController?.dismiss(animated: true, completion: {() -> Void in
self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0)
UIApplication.shared.delegate?.window??.makeKeyAndVisible()
if let statusBarStyle = self.previousStatusBarStyle {
self.setNeedsStatusBarAppearanceUpdate()
}
})
})
}
// In your view controller's scope
override var preferredStatusBarStyle: UIStatusBarStyle {
return previousStatusBarStyle ?? .default
}
}