pikacode/EBBannerView

iOS14崩溃

djroser opened this issue · 12 comments

SEGV_ACCERR EBBannerWindow hitTest:withEvent:

SEGV_ACCERR EBBannerWindow hitTest:withEvent:

keyWindow在iOS 14上已经废弃。
@Property(nullable, nonatomic,readonly) UIWindow *keyWindow API_DEPRECATED("Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes", ios(2.0, 13.0));

确实废弃了,不过我没办法复现这个崩溃,你也遇到这个崩溃了吗?

确实废弃了,不过我没办法复现这个崩溃,你也遇到这个崩溃了吗?

暂时还没复现这个bug。在第三方bug平台上收集的数据分析,一半是这个问题引起的。

可以加个qq或者微信交流下哈(QQ:798811246)

self.rootViewController.view.subviews 直接崩溃了

可以贴一下你的崩溃信息

我也遇到了在iOS14下,弹出customerbanner崩溃的问题。试了改了下,模拟器上看上去没啥问题,后面再观察一下。
以下是具体改动内容,希望大家批评指出。

#import "EBBannerView+Categories.h"

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
// if (CGRectContainsPoint(self.frame, point)) {
// return self;
// } else {
// return [super hitTest:point withEvent:event];
// }
return [super hitTest:point withEvent:event];
}

#import "EBBannerWindow.h"

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{

// __block UIView *view;
// [self.rootViewController.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// if (CGRectContainsPoint(obj.frame, point)) {
// view = obj;
// }
// }];
//
// if (view) {
// CGPoint point1 = [self convertPoint:point toView:view];
// return [view hitTest:point1 withEvent:event];
// } else {
// if (@available(iOS 13.0, *)) {
// return [UIApplication.sharedApplication.keyWindow hitTest:point withEvent:event];
// } else {
// return [super hitTest:point withEvent:event];
// }
// }

return [super hitTest:point withEvent:event];

}

-(void)dealloc{
// if (@available(iOS 13.0, *)) {
//
// } else {
// [self removeObserver:self forKeyPath:@"frame"];
// }

[self removeObserver:self forKeyPath:@"frame"];

}

#import "EBCustomBannerView.h"

-(void)show{

sharedWindow.hidden = NO;

[EBCustomBannerView sharedCustomBannerViewInit];

[sharedCustomViews addObject:self];

if (_maker.soundName || _maker.soundID != 0) {
    SystemSoundID soundID;
    if (_maker.soundName) {
        NSURL *url = [[NSBundle mainBundle] URLForResource:_maker.soundName withExtension:nil];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &soundID);
    } else {
        soundID = _maker.soundID;
    }
    WEAK_SELF(weakSelf);
    [[EBMuteDetector sharedDetecotr] detectComplete:^(BOOL isMute) {
        if (isMute && weakSelf.maker.vibrateOnMute) {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
        } else {
            AudioServicesPlaySystemSound(soundID);
        }
    }];
}

[sharedWindow.rootViewController.view addSubview:_maker.view];

if ([self currentAppearMode] == EBCustomViewAppearModeCenter) {
    dispatch_async(dispatch_get_main_queue(), ^{
        WEAK_SELF(weakSelf);
        UIView *view = weakSelf.maker.view;
        view.frame = [weakSelf showFrame];
        view.alpha = 0;
        [UIView animateWithDuration:weakSelf.maker.centerModeDurations[0].doubleValue animations:^{
            view.alpha = 1;
        }];
        view.alpha = 0;
        
        view.layer.shouldRasterize = YES;
        view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.4, 0.4);
        [UIView animateWithDuration:weakSelf.maker.centerModeDurations[1].doubleValue animations:^{
            view.alpha = 1;
            view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:weakSelf.maker.centerModeDurations[2].doubleValue delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
                view.alpha = 1;
                view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
            } completion:^(BOOL finished2) {
                view.layer.shouldRasterize = NO;
                if (weakSelf.maker.stayDuration > 0) {
                    [NSTimer eb_scheduledTimerWithTimeInterval:weakSelf.maker.stayDuration block:^(NSTimer *timer) {
                        [weakSelf hide];
                    } repeats:NO];
                }
            }];
        }];
    });
} else {
    _maker.view.frame = [self hideFrame];
    WEAK_SELF(weakSelf);
    [UIView animateWithDuration:_maker.animationDuration animations:^{
        weakSelf.maker.view.frame = [weakSelf showFrame];
    } completion:^(BOOL finished) {
        if (weakSelf.maker.stayDuration > 0) {
            [NSTimer eb_scheduledTimerWithTimeInterval:weakSelf.maker.stayDuration block:^(NSTimer *timer) {
                [weakSelf hide];
            } repeats:NO];
        }
    }];
}

}

-(void)hide{
if (!self.maker.view.superview) {
return;
}

if (_dismissBLock) { //由于这里有延迟关闭,且需要判断接听,这里需要回传
    _dismissBLock();
}

if ([self currentAppearMode] == EBCustomViewAppearModeCenter) {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        WEAK_SELF(weakSelf);
        UIView *view = weakSelf.maker.view;
        [UIView animateWithDuration:weakSelf.maker.centerModeDurations[0].doubleValue animations:^{
            view.alpha = 0;
        }];
        
        view.layer.shouldRasterize = YES;
        [UIView animateWithDuration:weakSelf.maker.centerModeDurations[2].doubleValue animations:^{
            view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
        } completion:^(BOOL finished){
            [UIView animateWithDuration:weakSelf.maker.centerModeDurations[1].doubleValue delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
                view.alpha = 0;
                view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.4, 0.4);
            } completion:^(BOOL finished){
                [view removeFromSuperview];
                [sharedCustomViews removeObject:weakSelf];
            }];
        }];
    });
    
} else {
    WEAK_SELF(weakSelf);
    [UIView animateWithDuration:_maker.animationDuration animations:^{
        weakSelf.maker.view.frame = [weakSelf hideFrame];
        
    } completion:^(BOOL finished) {
        
        if (weakSelf.maker.view.superview) {
            [weakSelf.maker.view removeFromSuperview];
        }
        if ([sharedCustomViews containsObject:weakSelf]) {
            [sharedCustomViews removeObject:weakSelf];
        }
        sharedWindow.hidden = YES;
    }];
}

}

哥们,你可以写一下问题的原因和解决思路

这个问题我已经解决上线了,大家可以看一下我的pull request,我正在尝试联系作者accept。

作者已经把我的PR合进去了,你可以下载最新的源码试试是否ok