问题
I am testing my app on iOS 12 with XCode 10 (the official non-beta release). During start-up in the simulator the UI of my app freezes for almost exactly 3 minutes in the middle of the fading from the launch screen to the normal screen. Does anybody know what could be causing this, or is it a bug in the simulator?
The app itself does not hang, only the UI. Any timers will still fire. Any busy thread will continue normally. If I rotate the phone, then the rotating notifications still arrive and get handled, just the UI does not change and does not react to any taps for 3 minutes. After the freeze it continues as if nothing happened. If I pause the app during the freeze in the XCode debugger, then all threads look fine, including the main thread. They are all in the "waiting for events" state.
The freezing occurs on all iOS-12 devices in the simulator. Devices in the simulator running older versions of iOS are fine. The behaviour on a real device running iOS 12 is fine. But I do not have a possibility to test on all real device types, so it may not work on some models.
Does anybody see the same behaviour and know what this could be caused by?
EDIT: Even if I terminate the app from Xcode during the freeze, the frozen UI will not disappear until after 3 minutes
EDIT 2: Even when I pause the execution of the app during the freeze period, the UI will still unfreeze and complete the startup animation after 3 minutes.
UPDATE: The problem seems to be caused by a specific CALayer in the app. In the following code:
UIColor *color = [UIColor colorWithRed:0 green:1.0 blue:1.0 alpha:1.0];
courseLineLayer = [CALayer layer];
courseLineLayer.contentsScale = [UIScreen mainScreen].scale;
courseLineLayer.backgroundColor = color.CGColor;
courseLineLayer.bounds = CGRectMake(0, 0, 3, 100);
courseLineLayer.anchorPoint = CGPointMake(0.5, 1.0);
courseLineLayer.masksToBounds = NO;
courseLineLayer.hidden = NO;
If I change the hidden = NO
to hidden = YES
then the problem disappears. I use plenty of CALayers in the app, and have no idea why this one is so special.
Note also that the whole screen freezes, and even the Home button is not working anymore.
If I configure the app such that this layer unhidden when coming out of sleep, then the screen is frozen halfway in the opening animation:
I have now created a bug for Apple to look at, maybe they know about it.
来源:https://stackoverflow.com/questions/52413278/ios-12-application-freezes-during-start-up