[iOSAppOnMac] ShareKit: Crashes in SHKItemIsPDF() or -[SHKSaveToFilesSharingService saveFileURL:completion:]

I have a custom document-based iOS app that also runs on macOS. After implementing -activityItemsConfiguration to enable sharing from the context menu, I found that the app crashes on macOS when selecting Share… from the context menu and then selecting Save (i.e. Save to Files under iOS). This problem does not occur on iOS, which behaves correctly.

- (id<UIActivityItemsConfigurationReading>)activityItemsConfiguration {
NSItemProvider * provider = [[NSItemProvider alloc] initWithContentsOfURL:self.document.presentedItemURL];
UIActivityItemsConfiguration * configuration = [UIActivityItemsConfiguration activityItemsConfigurationWithItemProviders:@[ provider ]];
// *** crashes with com.apple.share.System.SaveToFiles
return configuration;
}

Additionally, I found that to even reach this crash, the workaround implemented in the NSItemProvider (FBxxx) category of the sample project is needed. Without this, the app will crash much earlier, due to SHKItemIsPDF() erroneously invoking -pathExtension on an NSItemProvider. This appears to be a second bug in Apple’s private ShareKit framework.

#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
@implementation NSItemProvider (FBxxx)
// *** SHKItemIsPDF() invokes -pathExtension on an NSItemProvider (when running under macOS, anyway) -> crash
- (NSString *)pathExtension {
return self.registeredContentTypes.firstObject.preferredFilenameExtension;
}
@end

Again, this all works fine on iOS (17.5) but crashes when the exact same app build is running on macOS (14.5).

I believe these bugs are Apple's. Any idea how to avoid the crash? Is there a way to disable the "Save to Files" option in the sharing popup?

I filed FB13819800 with a sample project that demonstrates the crash on macOS. I was going to file a TSI to get this resolved, but I see that DTS is not responding to tech support incidents until after WWDC.

I also am facing this crash, in my case my using a SwiftUI ShareLink with a FileRepresentation specifying any file-like exportedContentType.

Did you find a solution?

I think I'm seeing something similar. I have a ShareLink with a string value and a Preview. If the user tries to save it to a file on iOS, it works fine. When I run the same on Mac (built for iPad, so not Mac Catalyst), I get a crash. All other options on the Share sheet works except Save to files. If I remove the preview, it removes the save to files option.

I wonder if it something to do with sandbox access for Mac apps built for iPad?

I am having a similar problem. I have an iOS app which works fine. When I run on my Mac (built for iPad, not Mac Catalyst) it crashes when trying to save to a file. It is crashing in the call SHKSaveToFilesSharingService->[NSSavePanel setNameFieldStringValue:]

I have attempted the share using simple text rather than a file and the results are the same. So the problem doesn't appear to be with saving a file, but rather with saving TO a file. This suggests that it is not a sandbox access problem.

Other share options work correctly, both with a file and a string.

I have same issue as well, when using Transferable in macOS with a .pdf or .file type I get the crash -[NSItemProvider pathExtension]: unrecognized selector sent to instance 0x600003a7d110

Another vote, SwiftUI ShareLink, saving a CSV.

Problem still occurs on macOS 15.5 (24F74).

I've received no updates from Apple in FB13819800 since filing this a year ago with sample project that reproduces the problem.

Could mean they're fixing it in Next Major OS, but we really should have a fix in macOS 15.x at least, preferably 13.x+ in my case.

For the record, here's the log up to the first exception on macOS 15.5:

Save: timed out loading URL
*** Assertion failure in -[NSSavePanel setNameFieldStringValue:], NSSavePanel.m:1347
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: aString != nil'
*** First throw call stack:
(
0 CoreFoundation 0x0000000195f32ca0 __exceptionPreprocess + 176
1 libobjc.A.dylib 0x00000001959f6b90 objc_exception_throw + 88
2 Foundation 0x0000000197541a78 -[NSCalendarDate initWithCoder:] + 0
3 AppKit 0x000000019aaedd90 -[NSSavePanel setNameFieldStringValue:] + 560
4 ShareKit 0x00000001c8953ce0 -[SHKSaveToFilesSharingService saveFileURL:completion:] + 116
5 ShareKit 0x00000001c89542b4 -[SHKSaveToFilesSharingService save:completion:] + 80
6 ShareKit 0x00000001c8954508 __49-[SHKSaveToFilesSharingService performWithItems:]_block_invoke.46 + 60
7 ShareKit 0x00000001c8919778 -[SHKSharingService _runActionBlockWithItems:completion:] + 144
8 ShareKit 0x00000001c891c8f8 -[SHKSharingService performCustomServiceWithItems:] + 348
9 ShareKit 0x00000001c891c6e8 -[SHKSharingService performWithItems:] + 2504
10 ShareKit 0x00000001c8954408 -[SHKSaveToFilesSharingService performWithItems:] + 296
11 ShareKit 0x00000001c891bcfc -[SHKSharingService performWithItems:completion:] + 64
12 ShareKit 0x00000001c892db50 -[SHKSharingServicePicker _performSharingService:] + 912
13 ShareKit 0x00000001c892dc64 -[SHKSharingServicePicker _handleItemsReady] + 76
14 ShareKit 0x00000001c8931c98 __55-[SHKSharingServicePicker _performItemLoadsIfNecessary]_block_invoke + 32
15 ShareKit 0x00000001c892a490 -[SHKSharingServicePicker _loadSendCopyRepresentationIfNecessaryWithCompletionHandler:] + 180
16 ShareKit 0x00000001c8931c3c -[SHKSharingServicePicker _performItemLoadsIfNecessary] + 128
17 ShareKit 0x00000001c8931b74 -[SHKSharingServicePicker _performSelectedService] + 1176
18 ShareKit 0x00000001c89356e8 -[SHKSharingServicePicker _performActionWithIdentifier:] + 356
19 ShareKit 0x00000001c8955374 __65-[SHKShareSheetRemoteViewController performActionWithIdentifier:]_block_invoke + 56
20 libdispatch.dylib 0x000000010342c514 _dispatch_call_block_and_release + 32
21 libdispatch.dylib 0x00000001034492dc _dispatch_client_callout + 16
22 libdispatch.dylib 0x000000010346cc94 _dispatch_main_queue_drain.cold.5 + 900
23 libdispatch.dylib 0x000000010343dd98 _dispatch_main_queue_drain + 180
24 libdispatch.dylib 0x000000010343dcd4 _dispatch_main_queue_callback_4CF + 44
25 CoreFoundation 0x0000000195effda4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
26 CoreFoundation 0x0000000195ec0a9c __CFRunLoopRun + 1980
27 CoreFoundation 0x0000000195ebfc58 CFRunLoopRunSpecific + 572
28 HIToolbox 0x00000001a195427c RunCurrentEventLoopInMode + 324
29 HIToolbox 0x00000001a19574e8 ReceiveNextEventCommon + 676
30 HIToolbox 0x00000001a1ae2484 _BlockUntilNextEventMatchingListInModeWithFilter + 76
31 AppKit 0x0000000199de7ab4 _DPSNextEvent + 684
32 AppKit 0x000000019a7865b0 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 688
33 AppKit 0x0000000199ddac64 -[NSApplication run] + 480
34 AppKit 0x0000000199db135c NSApplicationMain + 880
35 AppKit 0x0000000199ffdcf4 +[NSWindow _savedFrameFromString:] + 0
36 UIKitMacHelper 0x00000001b13e4164 UINSApplicationMain + 976
37 UIKitCore 0x00000001c9a57c9c UIApplicationMain + 148
38 MobileRC6502.debug.dylib 0x0000000103620590 __debug_main_executable_dylib_entry_point + 188
39 dyld 0x0000000195a36b98 start + 6076
)

Problem persists in macOS 26.0 Beta (25A5279m).

[iOSAppOnMac] ShareKit: Crashes in SHKItemIsPDF() or -[SHKSaveToFilesSharingService saveFileURL:completion:]
 
 
Q