I'm trying to access the UNUserNotificationCenter
from within a JavaFX application on macOS to send user notifications. Therefor, I'm using jfa which is a wrapper around jna to interact with apples foundation framework. With this, my code basically looks like the following:
NSBundle nsBundle = NSBundle.bundleWithPath("/System/Library/Frameworks/UserNotifications.framework");
nsBundle.load();
ID unUserNotificationCenter = nsBundle.classNamed("UNUserNotificationCenter");
// This call fails:
ID currentNotificationCenter = Foundation.invoke(unUserNotificationCenter, "currentNotificationCenter");
Accessing and loading the UserNotifications frameworks is working well, however i cannot manage to get the currentNotificationCenter
as this call fails with the following error:
2021-02-10 21:35:50.346 java[76301:37176563] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL file:///Users/jan/.sdkman/candidates/java/11.0.8-amzn/bin/'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff38d5cb57 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff71ba15bf objc_exception_throw + 48
2 CoreFoundation 0x00007fff38d85d08 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff3b477ead -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UserNotifications 0x00007fff468a7a66 __53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke + 911
5 libdispatch.dylib 0x00007fff72cf0658 _dispatch_client_callout + 8
6 libdispatch.dylib 0x00007fff72cf17de _dispatch_once_callout + 20
7 UserNotifications 0x00007fff468a76d5 +[UNUserNotificationCenter currentNotificationCenter] + 101
8 jna10020548276359543057.tmp 0x000000010c3c0e74 ffi_call_unix64 + 76
9 ??? 0x0000700008150ca8 0x0 + 123145437908136
)
I tried accessing the notification center at different times like when the application starts or e.g. when the user clicks a button to make sure that (hopefully) the application is completely loaded.
However, everything resulted in the same error. I tried the same code in a native macOS app in objective-c and everything worked well right away.
This is 100% reproducible, so I'm guessing I'm doing something wrong here or missing some required step. Does anyone maybe have an idea what may cause this?