The following code exports a file from my app's 'tmp' folder to other apps using UIActivityViewController
.
private func exportFile(_ fileURL: URL) {
let items: [Any] = [fileURL]
let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
present(activityViewController, animated: true, completion: nil)
}
This code was working fine and I could export to iCloud
, Google Drive
, Mail
, Outlook
and iZip
(the latter using 'Copy to iZip').
However, my app has recently started crashing after selecting 'Copy to iZip'
when exporting, though exporting to the other apps works fine. Between it working and crashing there have been updates to iOS, iZip and my app.
Crashlytics
reports the following, but this looks deep in iOS and it's difficult to know what the root cause of the problem is:
Fatal Exception: NSInvalidArgumentException *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
ShareSheet __79-[UIActivityViewController willPerformInServiceActivityWithRequest:completion:]_block_invoke_3
This occurs on an iPhone running iOS 13.3.1
Debugger report on breaking on NSInvalidArgumentException:
> (lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000189ffdf6c libobjc.A.dylib`objc_exception_throw
frame #1: 0x000000018a32c360 CoreFoundation`_CFThrowFormattedException + 112
frame #2: 0x000000018a32b9f4 CoreFoundation`-[__NSArrayM insertObject:atIndex:].cold.1 + 48
frame #3: 0x000000018a1ae120 CoreFoundation`-[__NSArrayM insertObject:atIndex:] + 1104
frame #4: 0x0000000195914e80 ShareSheet`__79-[UIActivityViewController willPerformInServiceActivityWithRequest:completion:]_block_invoke_3 + 1512
frame #5: 0x00000001089497fc libdispatch.dylib`_dispatch_call_block_and_release + 24
frame #6: 0x000000010894abd8 libdispatch.dylib`_dispatch_client_callout + 16
frame #7: 0x0000000108958c34 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1316
frame #8: 0x000000018a2545e4 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
frame #9: 0x000000018a24f5d8 CoreFoundation`__CFRunLoopRun + 2004
frame #10: 0x000000018a24eadc CoreFoundation`CFRunLoopRunSpecific + 464
frame #11: 0x00000001941ef328 GraphicsServices`GSEventRunModal + 104
frame #12: 0x000000018e35c63c UIKitCore`UIApplicationMain + 1936
* frame #13: 0x00000001024f1078 xApp`main at AppDelegate.swift:41:7
frame #14: 0x000000018a0d8360 libdyld.dylib`start + 4
(lldb)
Code at frame #4 breakpoint (0x195914e80):
> WTFLogLevel, WTF::Logger::LogSiteIdentifier const&, char const (&) [7], unsigned long const&) (.cold.1)
0x195914e80 <+1512>: mov x28, x23
0x195914e84 <+1516>: ldr x0, [x23, #0xba0]
0x195914e88 <+1520>: ldr x1, [sp, #0x38]
0x195914e8c <+1524>: mov x2, x25
0x195914e90 <+1528>: mov x3, x20
0x195914e94 <+1532>: bl 0x193904be4 ; symbol stub
Any idea what the problem might be? I'm not sure whether it's a problem with my app, iOS or iZip.