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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容