avoid crash on iOS9/10

pull/1/head
Michael Kirk 6 years ago
parent 9483566ef7
commit dbe8e5706d

@ -59,13 +59,14 @@ public class OWSNavigationBar: UINavigationBar {
private func applyTheme() {
guard respectsTheme else {
self.blurEffectView?.removeFromSuperview()
removeBlurEffectView()
self.setBackgroundImage(nil, for: .default)
return
}
if UIAccessibilityIsReduceTransparencyEnabled() {
self.blurEffectView?.removeFromSuperview()
removeBlurEffectView()
let color = Theme.navbarBackgroundColor
let backgroundImage = UIImage(color: color)
self.setBackgroundImage(backgroundImage, for: .default)
@ -80,6 +81,7 @@ public class OWSNavigationBar: UINavigationBar {
let blurEffectView: UIVisualEffectView = {
if let existingBlurEffectView = self.blurEffectView {
existingBlurEffectView.isHidden = false
return existingBlurEffectView
}
@ -194,6 +196,29 @@ public class OWSNavigationBar: UINavigationBar {
self.setBackgroundImage(UIImage(), for: .default)
self.shadowImage = UIImage()
self.clipsToBounds = true
self.blurEffectView?.isHidden = true
removeBlurEffectView()
}
// MARK:
private func removeBlurEffectView() {
// Avoid crash on iOS 10.3.3 and iOS 9.4.
//
// Last Exception Backtrace:
// 0 CoreFoundation 0x1b6bfb38 __exceptionPreprocess + 124 (NSException.m:165)
// 1 libobjc.A.dylib 0x1a947062 objc_exception_throw + 34 (objc-exception.mm:521)
// 2 CoreFoundation 0x1b6bfa80 +[NSException raise:format:] + 104 (NSException.m:140)
// 3 UIKit 0x20bfc9fe -[UINavigationBar removeConstraint:] + 84 (UINavigationBar.m:4618)
// 4 UIKit 0x208ee3d4 _UIViewRemoveConstraintsMadeDanglyByChangingSuperview + 534 // (NSLayoutConstraint_UIKitAdditions.m:4716)
// 5 UIKit 0x208ede90 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 40 // (UIView.m:9467)
// 6 UIKit 0x208edd6c -[UIView(Hierarchy) _postMovedFromSuperview:] + 710 (UIView.m:361)
// 7 UIKit 0x20bd19e8 __UIViewWasRemovedFromSuperview + 154 (UIView.m:8889)
// 8 UIKit 0x208ecf6a -[UIView(Hierarchy) removeFromSuperview] + 528 (UIView.m:8961)
// 9 SignalMessaging 0x1d42b64 OWSNavigationBar.applyTheme() + 218 (OWSNavigationBar.swift:62)
if #available(iOS 11, *) {
self.blurEffectView?.removeFromSuperview()
} else {
self.blurEffectView?.isHidden = true
}
}
}

Loading…
Cancel
Save