Background#
In the morning, some users suddenly reported a crash when using the recording function. Initially, it was thought to be a problem with the recent update of the app's new version, so a quick investigation was carried out.
Investigation#
First, on the test phone, debugging in the test environment revealed no crashes, which was a relief, indicating that not all users were affected, and it was not a problem caused by the new version.
Then, checking the logs on the Tingyun backend, it was found that the crash occurred in the initialization of the AVAudioRecorder method - [[AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];. It was puzzling, as it was just a simple initialization method, so why would it cause a crash?
Initially, it was speculated that perhaps the user had not granted recording permissions, leading to a crash when starting recording. After testing, it was found that if permissions were closed, a prompt to enable permissions would appear before entering the recording step, and it was not possible to proceed to the recording step.
Then, there was suspicion that perhaps the initialized URL was empty, or that the device did not support certain parameters in the recordSettings? After searching, it was found that there were entries for crashes caused by empty URLs, so most likely the issue here was also an empty URL during initialization.
Continuing the investigation, it was found that the initialized URL was in the local cache folder in the Audio folder, with the file name being a combination of date and time to avoid duplication, in the format yyyyMMdd_HHmmss. In theory, there should not have been an issue with it being empty, so where was the problem; hence, communicating with the user, it was reported that the problem occurred today, whereas it was fine before, and there was a recent upgrade to the 15.6.1 system. However, the test device at hand was also on iOS 15.6.1 and did not experience any crash issues, indicating that it was not related to the system version.
Further investigation revealed that the time shown in the Tingyun backend user crash logs did not match the time when the user reported the issue during screen recording? Could it be due to a change in system time? But would changing the system time cause a crash in initializing AVAudioRecorder? Without too much hope, after testing, it was found that, Yohoo, changing the time indeed caused a crash during recording initialization... Magical, hahaha, this was not my fault, quickly went back to find the user.
Upon further communication with the user, it was clarified that the user had not changed the time, only switched the date display from 24-hour format to 12-hour format, what... Could it be... Quickly went to verify, indeed setting the 12-hour format caused a crash... Why? The date format yyyyMMdd_HHmmss can indeed accommodate 12-hour format, but when the returned string is 20220829_上午104030, containing Chinese characters, using this Chinese text to generate a NSURL results in nil, and initializing AVAudioRecorder with nil leads to a crash... 😭 It was still my fault, no more excuses, quickly made the necessary changes.