Cordova未加载完时返回导致崩溃的解决办法

 

在cordova混合开发的iOS项目中,当从原生跳转到CDVViewController类型的H5页面时,如果页面没有加载完就通过导航按钮或者利用手势返回上一层会报以下错误(测试机系统为iOS9.3):

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x135936a80 of class UIView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x135c02d20> (

<NSKeyValueObservance 0x135c01b20: Observer: 0x1358f5990, Key path: frame, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x135c019b0>

<NSKeyValueObservance 0x135c02cf0: Observer: 0x1358f5990, Key path: bounds, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x135c02730>

)'

 

 

看错误的原因是某个UIView类型的对象deallocated的时候没有remove掉KVO,根据错误里面的Key Path:frame和bounds找到是一个插件的问题:CDVSplashScreen中使用了KVO,但是返回上一层时没有remove掉

[parentView addObserver:self forKeyPath:@"frame" options:0 context:nil];

[parentView addObserver:self forKeyPath:@"bounds" options:0 context:nil];

 

在它的- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context方法里是根据屏幕的方向更改加载图。因为我的项目只是竖屏,所以不需要这个功能,直接把这些相关代码注释掉即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值