invertase / notifee

⚛️ A feature rich notifications library for React Native.
https://notifee.app
Apache License 2.0
1.88k stars 228 forks source link

Share extension crashes with "bundleProxyForCurrentProcess is nil: mainBundle.bundleURL" #260

Closed lachenmayer closed 2 years ago

lachenmayer commented 2 years ago

Hi there, we are using Notifee in our app, and we separately also have a share extension target on iOS. Whenever I try to launch the share extension in the simulator (by attaching it to Safari & trying to share a URL), the following crash occurs:

2021-12-09 19:00:13.206871+0000 ShareExtension[55740:6287153] *** Assertion failure in +[UNUserNotificationCenter currentNotificationCenter], UNUserNotificationCenter.m:55
2021-12-09 19:00:13.261090+0000 ShareExtension[55740:6287153] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL file:///Users/harry/Library/Developer/CoreSimulator/Devices/0EFE94FE-FA23-4C47-BDA0-0F41BBE814DD/data/Containers/Bundle/Application/DBD00310-3F1A-44F2-A9D3-0C3F835479FB/Picnic.app/PlugIns/ShareExtension.appex/'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001122f6bb4 __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x000000010e7d8be7 objc_exception_throw + 48
    2   Foundation                          0x000000010f1c2c12 _userInfoForFileAndLine + 0
    3   UserNotifications                   0x000000010fb54871 __53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke + 1021
    4   libdispatch.dylib                   0x000000011605ca56 _dispatch_client_callout + 8
    5   libdispatch.dylib                   0x000000011605dca5 _dispatch_once_callout + 20
    6   UserNotifications                   0x000000010fb54472 +[UNUserNotificationCenter currentNotificationCenter] + 101
    7   ShareExtension                      0x0000000102495695 __46-[NotifeeCoreUNUserNotificationCenter observe]_block_invoke + 53
    8   libdispatch.dylib                   0x000000011605ca56 _dispatch_client_callout + 8
    9   libdispatch.dylib                   0x000000011605dca5 _dispatch_once_callout + 20
    10  ShareExtension                      0x0000000102495616 -[NotifeeCoreUNUserNotificationCenter observe] + 182
    11  ShareExtension                      0x00000001024950fc -[NotifeeCoreNSNotificationCenter application_onDidFinishLaunchingNotification:] + 92
    12  CoreFoundation                      0x0000000112236edc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    13  CoreFoundation                      0x0000000112236ea2 ___CFXRegistrationPost_block_invoke + 49
    14  CoreFoundation                      0x0000000112236404 _CFXRegistrationPost + 496
    15  CoreFoundation                      0x0000000112235d37 _CFXNotificationPost + 806
    16  Foundation                          0x000000010f23f653 -[NSNotificationCenter postNotificationName:object:userInfo:] + 82
    17  UIKitCore                           0x0000000130889bfb -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 4477
    18  UIKitCore                           0x000000013088f403 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1221
    19  UIKitCore                           0x000000013088c0a2 -[UIApplication __completeAndRunAsPlugin] + 350
    20  UIKitCore                           0x000000013088be55 -[UIApplication _run] + 914
    21  UIKitCore                           0x0000000130890a53 UIApplicationMain + 101
    22  libxpc.dylib                        0x0000000118008006 _xpc_objc_main + 351
    23  libxpc.dylib                        0x000000011800a050 xpc_main + 122
    24  Foundation                          0x000000010f395a3a service_connection_handler + 0
    25  PlugInKit                           0x0000000122f35fed __PLUGINKIT_CALLING_OUT_TO_CLIENT_SUBSYSTEM_FOR_BEGINUSING__ + 36977
    26  PlugInKit                           0x0000000122f35c88 __PLUGINKIT_CALLING_OUT_TO_CLIENT_SUBSYSTEM_FOR_BEGINUSING__ + 36108
    27  PlugInKit                           0x0000000122f363b3 __PLUGINKIT_CALLING_OUT_TO_CLIENT_SUBSYSTEM_FOR_BEGINUSING__ + 37943
    28  ExtensionFoundation                 0x000000012464d6ae EXExtensionMain + 284
    29  Foundation                          0x000000010f2d0e4c NSExtensionMain + 240
    30  dyld                                0x000000010e547e1e start_sim + 10
    31  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_FRAMEWORK_PATH=/Users/harry/Library/Developer/Xcode/DerivedData/Picnic-emhdxftrbjekcpfmjliucubhxaco/Build/Products/Debug-iphonesimulator DYLD_LIBRARY_PATH=/Users/harry/Library/Developer/Xcode/DerivedData/Picnic-emhdxftrbjekcpfmjliucubhxaco/Build/Products/Debug-iphonesimulator DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL file:///Users/harry/Library/Developer/CoreSimulator/Devices/0EFE94FE-FA23-4C47-BDA0-0F41BBE814DD/data/Containers/Bundle/Application/DBD00310-3F1A-44F2-A9D3-0C3F835479FB/Picnic.app/PlugIns/ShareExtension.appex/'
_LSContextInitReturningError() failed with error Error Domain=NSOSStatusErrorDomain Code=-10817 "(null)" UserInfo={_LSFunction=_LSSchemaConfigureForStore, ExpectedSimulatorHash={length = 32, bytes = 0x8367042c 5a0d3739 c4750e92 134b458d ... 2bd5ba9c f73141f5 }, _LSLine=405, WrongSimulatorHash={length = 32, bytes = 0x2bea4bde a7079a50 310364fe 5294f4b1 ... 1a2344cc eb36b0fc }}
CoreSimulator 776.4 - Device: iPhone 13 (0EFE94FE-FA23-4C47-BDA0-0F41BBE814DD) - Runtime: iOS 15.0 (19A339) - DeviceType: iPhone 13

You can see the crash clearly here:

image

Versions:

Our share extension does not use/need any Notifee features at all -- is there some way of disabling the Notifee native dependency, eg. by removing the pod from the share extension target?

Thanks a lot!

mikehardy commented 2 years ago

I'm inexperienced with extensions on the iOS side but I do have multiple targets in my react-native app as my strategy for handling multiple firebase backends (I use one target per backend)

I have an abstract pod target in my Podfile with all the pods I want, then specific pod targets for each Xcode target, where I tune things - perhaps this is a way to enable or disable notifee? I'm unsure how to exclude something form auto-linking and then only include it in one target but Podfiles do allow full control via ruby etc so might be possible?


abstract_target 'Komp.ai' do

  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => true
  )

  # Required by react-native-permissions
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars"
  pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
  pod 'Permission-Motion', :path => "#{permissions_path}/Motion"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
  pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders"

  # Use pre-compiled FirebaseFirestore
  pod 'FirebaseFirestore/WithLeveldb', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => $FirebaseSDKVersion
  $RNFirebaseAnalyticsWithoutAdIdSupport = true

  target 'Komp.aiTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'Komp.aiDev' do
  end

  target 'Komp.aiTest' do
  end

that said, perhaps something may be done about the crash, and/or something is not correct about how the app is doing things with shared extensions

I seem to remember there was something fishy there - it is still unresolved:

https://github.com/invertase/notifee/issues/242

None of this is a solution really but perhaps it gets you closer to one?

helenaford commented 2 years ago

in your share extension, do you need all your react-native deps excluding notifee? If you don't need them, I'd say exclude all from your share extension.

lachenmayer commented 2 years ago

Thanks both for your quick help!

@helenaford We don't need Notifee at all, and I'm sure it would help to remove other unused dependencies from the target as well - I'm just not sure how! use_native_modules! adds each podspec defined by a node module as a pod rule. From what I can tell, there's no way of disabling any modules here. Do you know if there's any other way of doing this?

@mikehardy We are already using config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO' in our podfile, we needed it to get React Native running at all in the share extension (probably due to similar issues).

mikehardy commented 2 years ago

The best bet might be to have the share extension be completely different podfile target to keep it separate from the react-native auto-ilnker

helenaford commented 2 years ago

@lachenmayer I posted the other day an example of how to keep dependencies separate using targets here, if that helps at all? Hard to say exactly what you need to do without seeing your Podfile and your workspace

helenaford commented 2 years ago

I believe the issue is resolved. Please re-open if you're still experiencing it