Adding Product Module Name to NSExtensionPrincipalClass in FinderSync plist crashes it
Asked Answered
T

1

3

My cocoa application has a finder sync extension.

As suggested in the Apple guide: https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/Finder.html

I added $(PRODUCT_MODULE_NAME) to my finder's info.plist.

Doing this has caused the finder to crash even before it hits the init point.

Even my uncaught exception handler isn't able to catch this exception.

My extension's info.plist file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>My App Finder Integration</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>XPC!</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSMinimumSystemVersion</key>
    <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
    <key>LSUIElement</key>
    <true/>
    <key>NSExtension</key>
    <dict>
        <key>NSExtensionAttributes</key>
        <dict/>
        <key>NSExtensionPointIdentifier</key>
        <string>com.apple.FinderSync</string>
        <key>NSExtensionPrincipalClass</key>
        <string>$(PRODUCT_MODULE_NAME).FinderSync</string>
    </dict>
    <key>NSHumanReadableCopyright</key>
    <string>Copyright © 2017. All rights reserved.</string>
    <key>NSPrincipalClass</key>
    <string>NSApplication</string>
    <key>NSSupportsAutomaticGraphicsSwitching</key>
    <true/>
</dict>
</plist>

The error stack trace is:

2017-05-25 14:53:52.231849 My App Finder Integration[6258:60938] [General] *** setObjectForKey: object cannot be nil (key: F376D0DD-5E4B-4E4F-9BAF-D685C62BE59D)
2017-05-25 14:53:52.232218 My App Finder Integration[6258:60938] [General] (
    0   CoreFoundation                      0x00007fffa968d0db __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fffbe314a2a objc_exception_throw + 48
    2   CoreFoundation                      0x00007fffa958d115 -[__NSDictionaryM setObject:forKey:] + 1061
    3   Foundation                          0x00007fffab19a5a4 -[_NSExtensionContextVendor _setPrincipalObject:forUUID:] + 106
    4   Foundation                          0x00007fffab199d70 __105-[_NSExtensionContextVendor _beginRequestWithExtensionItems:listenerEndpoint:withContextUUID:completion:]_block_invoke + 883
    5   libdispatch.dylib                   0x00007fffbebc8ef7 _dispatch_call_block_and_release + 12
    6   libdispatch.dylib                   0x00007fffbebc00b8 _dispatch_client_callout + 8
    7   libdispatch.dylib                   0x00007fffbebcdb4b _dispatch_main_queue_callback_4CF + 925
    8   CoreFoundation                      0x00007fffa9643669 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    9   CoreFoundation                      0x00007fffa960465d __CFRunLoopRun + 2221
    10  CoreFoundation                      0x00007fffa9603b54 CFRunLoopRunSpecific + 420
    11  HIToolbox                           0x00007fffa8b8ea5c RunCurrentEventLoopInMode + 240
    12  HIToolbox                           0x00007fffa8b8e891 ReceiveNextEventCommon + 432
    13  HIToolbox                           0x00007fffa8b8e6c6 _BlockUntilNextEventMatchingListInModeWithFilter + 71
    14  AppKit                              0x00007fffa71345b4 _DPSNextEvent + 1120
    15  AppKit                              0x00007fffa78aed6b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2789
    16  AppKit                              0x00007fffa7128f35 -[NSApplication run] + 926
    17  AppKit                              0x00007fffa70f3850 NSApplicationMain + 1237
    18  libxpc.dylib                        0x00007fffbee5a8c7 _xpc_objc_main + 775
    19  libxpc.dylib                        0x00007fffbee592e4 xpc_main + 494
    20  Foundation                          0x00007fffab09415b +[NSXPCListener serviceListener] + 0
    21  PlugInKit                           0x00007fffb9feb41c -[PKService run] + 865
    22  PlugInKit                           0x00007fffb9feaf89 +[PKService main] + 55
    23  PlugInKit                           0x00007fffb9feb440 +[PKService _defaultRun:arguments:] + 17
    24  Foundation                          0x00007fffab2362bc NSExtensionMain + 51
    25  libdyld.dylib                       0x00007fffbebf6255 start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)
2017-05-25 14:53:52.232447 My App Finder Integration[6258:60938] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: F376D0DD-5E4B-4E4F-9BAF-D685C62BE59D)'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fffa968d0db __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fffbe314a2a objc_exception_throw + 48
    2   CoreFoundation                      0x00007fffa958d115 -[__NSDictionaryM setObject:forKey:] + 1061
    3   Foundation                          0x00007fffab19a5a4 -[_NSExtensionContextVendor _setPrincipalObject:forUUID:] + 106
    4   Foundation                          0x00007fffab199d70 __105-[_NSExtensionContextVendor _beginRequestWithExtensionItems:listenerEndpoint:withContextUUID:completion:]_block_invoke + 883
    5   libdispatch.dylib                   0x00007fffbebc8ef7 _dispatch_call_block_and_release + 12
    6   libdispatch.dylib                   0x00007fffbebc00b8 _dispatch_client_callout + 8
    7   libdispatch.dylib                   0x00007fffbebcdb4b _dispatch_main_queue_callback_4CF + 925
    8   CoreFoundation                      0x00007fffa9643669 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    9   CoreFoundation                      0x00007fffa960465d __CFRunLoopRun + 2221
    10  CoreFoundation                      0x00007fffa9603b54 CFRunLoopRunSpecific + 420
    11  HIToolbox                           0x00007fffa8b8ea5c RunCurrentEventLoopInMode + 240
    12  HIToolbox                           0x00007fffa8b8e891 ReceiveNextEventCommon + 432
    13  HIToolbox                           0x00007fffa8b8e6c6 _BlockUntilNextEventMatchingListInModeWithFilter + 71
    14  AppKit                              0x00007fffa71345b4 _DPSNextEvent + 1120
    15  AppKit                              0x00007fffa78aed6b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2789
    16  AppKit                              0x00007fffa7128f35 -[NSApplication run] + 926
    17  AppKit                              0x00007fffa70f3850 NSApplicationMain + 1237
    18  libxpc.dylib                        0x00007fffbee5a8c7 _xpc_objc_main + 775
    19  libxpc.dylib                        0x00007fffbee592e4 xpc_main + 494
    20  Foundation                          0x00007fffab09415b +[NSXPCListener serviceListener] + 0
    21  PlugInKit                           0x00007fffb9feb41c -[PKService run] + 865
    22  PlugInKit                           0x00007fffb9feaf89 +[PKService main] + 55
    23  PlugInKit                           0x00007fffb9feb440 +[PKService _defaultRun:arguments:] + 17
    24  Foundation                          0x00007fffab2362bc NSExtensionMain + 51
    25  libdyld.dylib                       0x00007fffbebf6255 start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Transformer answered 22/5, 2017 at 16:26 Comment(10)
Do not add text as image. Add the stacktrace for the crashing thread.Pedometer
Did you debug the crashed method?Pedometer
The app crashes before the init method for the finder sync starts.Transformer
So OverlayPathsMap isn't a class written by you?Pedometer
OverlayPathsMap is a class written by me, but it doesn't throw an exception where it is mentioned in the stack trace.Transformer
Just removing $(PRODUCT_MODULE_NAME) and making no other change, doesn't crash the app. It runs as expected.Transformer
So the crash is in your code. Inside -setDictValueAndOverlayIconForPath: you try to set a nil value in a dictionary.Pedometer
I assumed that was the case and added a null check. Still facing the issue. Have updated the question with the same.Transformer
Also, I am certain that adding $(PRODUCT_MODULE_NAME) is causing the code to execute in a different fashion. I say so because, the same code line works if i use FinderSync instead of $(PRODUCT_MODULE_NAME).FinderSync for the NSExtensionPrincipalClass keyTransformer
Neither I can see the code nor the additional null check.Pedometer
T
0

Xcode 15 displays an error when you use a Swift class without that formatting, which is the opposite of your scenario... but the error says:

__extensionPrincipalClass != nil - /Library/Caches/com.apple.xbs/Sources/ExtensionFoundation_Sim/ExtensionFoundation/Source/NSExtension/NSExtensionSupport/EXConcreteExtensionContextVendor.m:109: Unable to find NSExtensionPrincipalClass (MessagesViewController) in extension bundle! Please verify that the extension links the required frameworks and that the value for NSExtensionPrincipalClass is prefixed with '$(PRODUCT_MODULE_NAME).' if the class is implemented in Swift. Type: Fault | Timestamp: 2023-09-19 18:05:10.722854-07:00 | Library: ExtensionFoundation | Subsystem: com.apple.extensionkit | Category: default | TID: 0x4f172

(emphasis mine)

So I think it is likely that for O-C, you need to just put the class name.

Tommy answered 20/9, 2023 at 22:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.