今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

Fixing iOS beta4 crashes

iOS beta4 Crash Fix#

Preface#

After upgrading to iOS Beta4, some users reported that our app crashes when they use it, whether it's logging in or viewing details. We also found that the crash rate has increased by 0.02% based on Bugly data, exceeding the specified crash threshold. Although it is caused by upgrading to the beta version of the system, we still need to identify the specific cause and adapt as soon as possible. So let me talk about the API I found that caused the crash for your reference.

Investigation#

Since the crash is reproducible, it is easy to investigate. Find a phone that has been upgraded to iOS 14 beta4, then reproduce the steps and see where the crash occurs.
Our app crashes because we use the SexyJson library. In the SexyJsonProtocol class, line 67, the method sexyToValue() uses AnyRandomAccessCollection, and there is a force-unwrapped property. In previous system versions, the value returned at this point was not empty, so there was no problem. However, in this version, this property returns empty, causing the crash in the new system.

Location shown in the image:

Fix#

Since it is caused by force-unwrapping, the direct fix is to change the force-unwrapped part to the format of if let. After the modification, run it, bingo, the crash is indeed gone. However, during the verification process, although this part no longer crashes, the values that should normally exist are still missing. In other words, all requests that use this method to convert to a parameter dictionary have failed... Are you scared? Fortunately, we have thrown an error directly here, otherwise we would have thought that it was fixed and released it. The server-side would curse us because they would find a high error rate in the interface. After careful analysis of the implementation of this part, it was found that Mirror is used to obtain all properties in the class and generate a dictionary. Step by step debugging will reveal that Mirror class is still working normally, and mirror.children is also unaffected. However, AnyRandomAccessCollection(mirror.children) returns empty, so it is AnyRandomAccessCollection() that does not work properly in iOS 14 beta4. So I made another modification.

As shown in the image, the first modification:

The second modification:

Finally#

Therefore, the crash in our project on iOS 14 beta4 is caused by force-unwrapping in the SexyJson library, but the real reason is that the method AnyRandomAccessCollection() does not work properly in iOS 14 beta4.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.