iOS 13 适配 部分解决方案

iOS 13 平台运行崩溃

输出台报:
Terminating app due to uncaught exception 'NSGenericException', reason: ........

可能就是某条私有属性被禁用了。

比如以下例子崩溃日志如下:

Terminating app due to uncaught exception 'NSGenericException',
 reason: 'Access to _UIBarBackground's _backgroundEffectView ivar is prohibited. 
This is an application bug'

通过访问导航栏私有视图 _backgroundEffectView 并设置其透明度来达到导航栏透明的效果,这条私有属性被禁用了,UIView *barBackgroundView = self.navigationBar.subviews.firstObject; 可以直接拿到设置。

- (void)setNavigationBarBackgroundAlpha:(CGFloat)alpha {
    UIView *barBackgroundView = self.navigationBar.subviews.firstObject;
    if (@available(iOS 13.0, *)) {
        barBackgroundView.alpha = alpha;
        return;
    }
    // 处理底部分割线
    UIView *shadowView = [barBackgroundView valueForKey:@"_shadowView"];
    shadowView.hidden = (alpha < 1.0);
    // 处理背景
    if (self.navigationBar.isTranslucent) {
        if (@available(iOS 10.0, *)) {
            UIView *backgroundEffectView = [barBackgroundView valueForKey:@"_backgroundEffectView"];
            backgroundEffectView.alpha = alpha;
        } else {
            UIView *adaptiveBackdrop = [barBackgroundView valueForKey:@"_adaptiveBackdrop"];
            adaptiveBackdrop.alpha = alpha;
        }
    } else {
        barBackgroundView.alpha = alpha;
    }
}

另外:
如果使用到蓝牙通讯
需要在info.plist里面添加

NSBletoothAlwaysUsageDescription
和 Privacy - Bluetooth Peripheral Usage Description

image.png

你可能感兴趣的:(iOS 13 适配 部分解决方案)