App crash after update to IOS 18

After update to IOS18, my app crashed. following is the exception got from xcode:

Trapped uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager createDirectoryAtURL:withIntermediateDirectories:attributes:error:]: URL is nil' ( 0 CoreFoundation 0x0000000194a79098 47427277-EE15-3C17-AD68-6886B0380B5E + 540824 1 libobjc.A.dylib 0x0000000191d7b2e4 objc_exception_throw + 88 2 Foundation 0x0000000193741f48 12E17A7A-B65F-35EE-82D7-CBC31004E223 + 1154888 3 CFNetwork 0x0000000195eeb2bc FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 164540 4 CFNetwork 0x0000000195eeac7c FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 162940 5 libdispatch.dylib 0x000000010342a71c _dispatch_client_callout + 20 6 libdispatch.dylib 0x000000010343bf04 _dispatch_lane_barrier_sync_invoke_and_complete + 176 7 CFNetwork 0x0000000195eeaa88 FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 162440 8 CFNetwork 0x0000000195ee9b20 FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 158496 9 CFNetwork 0x0000000195ee95f4 FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 157172 10 CFNetwork 0x0000000195ee907c FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 155772 11 CFNetwork 0x0000000195ee34b0 FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 132272 12 CFNetwork 0x0000000195f942c4 FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 856772 13 CFNetwork 0x0000000195f94214 FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 856596 14 CFNetwork 0x0000000195f9330c FA95B718-E8EB-34BD-90FA-8FB1AFE016D6 + 852748 15 libdispatch.dylib 0x0000000103428a30 _dispatch_call_block_and_release + 32 16 libdispatch.dylib 0x000000010342a71c _dispatch_client_callout + 20 17 libdispatch.dylib 0x00000001034325e8 _dispatch_lane_serial_drain + 828 18 libdispatch.dylib 0x0000000103433394 _dispatch_lane_invoke + 460 19 libdispatch.dylib 0x0000000103434b20 _dispatch_workloop_invoke + 2264 20 libdispatch.dylib 0x00000001034405f0 _dispatch_root_queue_drain_deferred_wlh + 328 21 libdispatch.dylib 0x000000010343fc00 _dispatch_workloop_worker_thread + 580 22 libsystem_pthread.dylib 0x000000021bddfc7c _pthread_wqthread + 288 23 libsystem_pthread.dylib 0x000000021bddc488 start_wqthread + 8 )

This app works fine until ios 18 appear. Could you help me? thanks

Answered by DTS Engineer in 804578022

Sadly, that crash report shows that you’re using a third-party crash reporter (see thread 8, frame 6) and that’s severely undermines my confidence in it. See Implementing Your Own Crash Reporter for an explanation as to why I don’t trust third-party crash reporters.

Are you able to reproduce this in your office? If so, try removing the third-party crash reporter and reproducing it again. Presuming it still crashes, post the resulting crash report.

If you’re not able to reproduce this, you have a decision to make: How wedded are you to this third-party crash reporter? If you can’t live without it, it’s going to be challenging to make progress on this crash. OTOH, if you’re not particularly wedded to it, I recommend that you ship an update to your app with it removed and then see what crash reports you get back.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It’s hard to say what’s going on here without more details. Please post a full Apple crash report. See Posting a Crash Report for advice on how to do that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for your reply, I login with my apple developer id, and please see the attached crash report. hoping to get your reply soon. thanks! Simonlll

Sadly, that crash report shows that you’re using a third-party crash reporter (see thread 8, frame 6) and that’s severely undermines my confidence in it. See Implementing Your Own Crash Reporter for an explanation as to why I don’t trust third-party crash reporters.

Are you able to reproduce this in your office? If so, try removing the third-party crash reporter and reproducing it again. Presuming it still crashes, post the resulting crash report.

If you’re not able to reproduce this, you have a decision to make: How wedded are you to this third-party crash reporter? If you can’t live without it, it’s going to be challenging to make progress on this crash. OTOH, if you’re not particularly wedded to it, I recommend that you ship an update to your app with it removed and then see what crash reports you get back.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi, Thanks for your reply, I have removed 3rd part crash report in the project and archived and reinstalled again. But I don't know why there are 3 reports, so I uploaded all of them.

Accepted Answer

Thanks for the Apple crash reports.

Looking at that first crash report, I see that it’s crashing due to an unhandled language exception. The Last Exception Backtrace section shows this:

Last Exception Backtrace:
0 CoreFoundation  … __exceptionPreprocess + 164
1 libobjc.A.dylib … objc_exception_throw + 87
2 Foundation      … -[NSFileManager createDirectoryAtURL:withIntermediateDirectories:attributes:error:] + 127
3 CFNetwork       … -[_NSHTTPAlternativeServicesStorage _onqueue_initializeDatabaseIfNotEmpty:] + 331

That’s an interesting crash. Frame 2 shows that the exception was thrown by -createDirectoryAtURL:…. The only likely explanation for that is that the incoming URL is nil. Which brings us to frame 3. The code for that looks something like this:

NSURL * lib = [NSFileManager.defaultManager URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask].firstObject;
NSURL * nested1 = [lib URLByAppendingPathComponent:name1 isDirectory:YES];
NSURL * nested2 = [nested1 URLByAppendingPathComponent:name2 isDirectory:YES];
[NSFileManager.defaultManager createDirectoryAtURL:nested2 withIntermediateDirectories:YES attributes:nil error:nil];

The only way that nested2 can be nil is if -URLsForDirectory:inDomains: returned @[] (or nil). It’s hard to see how that can happen if the app is behaving normally.

We’ve seen a few reports of problems like this before (r. 132595024) and our investigation suggests that this is caused by code within your app swizzling methods on NSFileManager. Swizzling methods in system classes is a bad idea, and something we most definitely don’t support [1].

I recommend that you first check to see if it’s your code that’s swizzling NSFileManager. If it is, please stop doing that.

However, I suspect that it’s not your code doing this, but some third-party library. You should look through the libraries you’re using to identify which one is doing this swizzling. Once you work that out, you can then raise this problem with its author.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] In this case it was broken by the significant implementation changes we made as part of this effort: What’s next for Foundation

If you were using Objective C and instantiating NSFileManager incorrectly(for example, alloc but no init), it would still work in earlier versions of iOS, but it will fail in iOS 18.

Hi, The problem is solved. Just as you said I found a third-party Framework which functioned as data collection. it's website explain the theory:By using the runtime characteristics of objective-c and the Method swizzle technology, the method implementation corresponding to the selector can be replaced at runtime to achieve the purpose of hooking the method. That is to say, after embedding the Keynote SDK, at the beginning of the program startup, the Keynote SDK will perform the swizzle operation on the corresponding method, so that when calling a swizzled function, the corresponding custom function of the SDK will be called first, and some data collection operations will be performed in the SDK function, and then the SDK function will be called back to the original function implementation, which will not affect the original program logic. I removed this framework, and app run smoothly in ios 18 now. Thanks for your help.

App crash after update to IOS 18
 
 
Q