今是昨非

今是昨非

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

iOS beta4 crash fix

title: iOS beta4 Crash Fix
tags:
- Technology
- iOS
date: 2020-08-10 10:57#

iOS beta4 Crash Fix#

Introduction#

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 noticed an increase of 0.02% in crash rate based on Bugly data, which exceeds the specified crash threshold. Although this 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, I will explain which API I found to be the cause for reference.

Investigation#

Since the crash is reproducible, it is easy to investigate. Find a phone that has been upgraded to iOS 14 beta4, reproduce the steps, and observe the exact location of the crash.
In our app, we use the library SexyJson. In the class SexyJsonProtocol, on line 67, the method sexyToValue() uses AnyRandomAccessCollection, which has 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 if let format. After the modification, run the app and voila, the crash is indeed gone. However, during the verification process, although the crash is gone, the values that should normally exist are still missing. In other words, all requests that use this method to convert objects to parameter dictionaries have failed. Fortunately, we have error reporting in this part, otherwise, we would have mistakenly thought that it was fixed and released it. The server-side would have scolded us because they would have noticed a high error rate in the interfaces. After careful analysis of the implementation in this part, it was found that Mirror is used to obtain all properties of the class and generate a dictionary. Step by step debugging reveals that Mirror class is still working fine, and mirror.children is also unaffected. However, AnyRandomAccessCollection(mirror.children) returns empty, indicating that AnyRandomAccessCollection() method does not work properly in iOS 14 beta4. So, another modification is needed.

As shown in the image, first modification:

Second modification:

Conclusion#

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.