ryanmcgrath / cacao

Rust bindings for AppKit (macOS) and UIKit (iOS/tvOS). Experimental, but working!
MIT License
1.86k stars 69 forks source link

[Question] Desktop notification seems not work? #19

Open 24seconds opened 2 years ago

24seconds commented 2 years ago

Hello, I'm testing desktop notification using cacao in my repo, cacao_playground.

I just added one line for notification based on hello world. But I get an error like this when I run cargo run. I saw a readme in cacao but doesn't understand this word

Note that this requires your application be code-signed, and will not work without it.

What am I doing wrong?

❯ cargo run
   Compiling cacao_playground v0.1.0 (/Users/young/Desktop/moloco/playground/rust/cacao_playground)
    Finished dev [unoptimized + debuginfo] target(s) in 1.15s
     Running `target/debug/cacao_playground`
2021-10-24 13:24:19.446 cacao_playground[46977:5130533] *** Assertion failure in +[UNUserNotificationCenter currentNotificationCenter], UNUserNotificationCenter.m:54
2021-10-24 13:24:19.449 cacao_playground[46977:5130533] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL file:///Users/young/Desktop/moloco/playground/rust/cacao_playground/target/debug/'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff205f81db __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007fff20331d92 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff20621352 +[NSException raise:format:arguments:] + 88
    3   Foundation                          0x00007fff213e04d2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
    4   UserNotifications                   0x00007fff2a4fa540 __53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke + 985
    5   libdispatch.dylib                   0x00007fff202dc806 _dispatch_client_callout + 8
    6   libdispatch.dylib                   0x00007fff202dd98c _dispatch_once_callout + 20
    7   UserNotifications                   0x00007fff2a4fa165 +[UNUserNotificationCenter currentNotificationCenter] + 101
    8   cacao_playground                    0x000000010d540be6 _ZN60_$LT$$LP$$RP$$u20$as$u20$objc..message..MessageArguments$GT$6invoke17h3fc300ea76f1fcadE + 70
    9   cacao_playground                    0x000000010d53f282 _ZN4objc7message8platform15send_unverified17he01a71148119e4eaE + 98
    10  cacao_playground                    0x000000010d54024b _ZN5cacao18user_notifications18NotificationCenter6notify17h59789fbb44092ba5E + 2619
    11  cacao_playground                    0x000000010d52a77c _ZN85_$LT$cacao_playground..BasicApp$u20$as$u20$cacao..macos..app..traits..AppDelegate$GT$20did_finish_launching17h9887249749ff2e54E + 108
    12  cacao_playground                    0x000000010d52b5ce _ZN5cacao5macos3app8delegate20did_finish_launching17h35985f97e2106380E + 46
    13  CoreFoundation                      0x00007fff20573a53 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    14  CoreFoundation                      0x00007fff2060f4d9 ___CFXRegistrationPost_block_invoke + 49
    15  CoreFoundation                      0x00007fff2060f454 _CFXRegistrationPost + 496
    16  CoreFoundation                      0x00007fff20544cce _CFXNotificationPost + 736
    17  Foundation                          0x00007fff212b6bb8 -[NSNotificationCenter postNotificationName:object:userInfo:] + 59
    18  AppKit                              0x00007fff22d8e440 -[NSApplication _postDidFinishNotification] + 305
    19  AppKit                              0x00007fff22d8e192 -[NSApplication _sendFinishLaunchingNotification] + 208
    20  AppKit                              0x00007fff22d8b331 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 541
    21  AppKit                              0x00007fff22d8af87 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665
    22  Foundation                          0x00007fff212e2306 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308
    23  Foundation                          0x00007fff212e2176 _NSAppleEventManagerGenericHandler + 80
    24  AE                                  0x00007fff2635e7f3 _AppleEventsCheckInAppWithBlock + 15720
    25  AE                                  0x00007fff2635df0e _AppleEventsCheckInAppWithBlock + 13443
    26  AE                                  0x00007fff26356c23 aeProcessAppleEvent + 448
    27  HIToolbox                           0x00007fff287d6012 AEProcessAppleEvent + 54
    28  AppKit                              0x00007fff22d85610 _DPSNextEvent + 2046
    29  AppKit                              0x00007fff22d83945 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1364
    30  AppKit                              0x00007fff22d75c69 -[NSApplication run] + 586
    31  cacao_playground                    0x000000010d540b96 _ZN60_$LT$$LP$$RP$$u20$as$u20$objc..message..MessageArguments$GT$6invoke17h11fd747e9c6b6bd4E + 70
    32  cacao_playground                    0x000000010d53eccc _ZN4objc7message8platform15send_unverified17h66e57c952470fa58E + 92
    33  cacao_playground                    0x000000010d5307c6 _ZN5cacao5macos3app12App$LT$T$GT$3run17h185027ef278d9109E + 1206
    34  cacao_playground                    0x000000010d52a7cb _ZN16cacao_playground4main17hf4adb535eeac4ec1E + 59
    35  cacao_playground                    0x000000010d529d4e _ZN4core3ops8function6FnOnce9call_once17hfad80ba2a9fe4a31E + 14
    36  cacao_playground                    0x000000010d531021 _ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17he91fbb5a9ef377b9E + 17
    37  cacao_playground                    0x000000010d52ab94 _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h48ed62f72d20011eE + 20
    38  cacao_playground                    0x000000010d5d087a _ZN3std2rt19lang_start_internal17h9fcc861d49447111E + 650
    39  cacao_playground                    0x000000010d52ab5e _ZN3std2rt10lang_start17h96fe9822a85ecbd5E + 46
    40  cacao_playground                    0x000000010d52a856 main + 22
    41  libdyld.dylib                       0x00007fff204a1f3d start + 1
)
libc++abi: terminating with uncaught exception of type NSException
[1]    46977 abort      cargo run
ryanmcgrath commented 2 years ago

Yup, that API is blocked (by Apple) behind code signing requirements. You should look up how to run codesign - and you might want to use cargo-bundle to make life easier. The iOS example in this repository does use codesign IIRC.

I should probably throw together a demo of this. Alas, I am sitting in a bar with my wife right now so this… will wait, lol

(I will say, if it compiles, your Rust side is likely correct)

On Sat, Oct 23, 2021 at 21:26, 24seconds @.***> wrote:

Hello, I'm testing desktop notification using cacao in my repo, cacao_playground.

I just added one line for notification based on hello world. But I get an error like this when I run cargo run. I saw a readme in cacao but doesn't understand this word

Note that this requires your application be code-signed, and will not work without it.

What am I doing wrong?

❯ cargo run Compiling cacao_playground v0.1.0 (/Users/young/Desktop/moloco/playground/rust/cacao_playground) Finished dev [unoptimized + debuginfo] target(s) in 1.15s Running target/debug/cacao_playground 2021-10-24 13:24:19.446 cacao_playground[46977:5130533] Assertion failure in +[UNUserNotificationCenter currentNotificationCenter], UNUserNotificationCenter.m:54 2021-10-24 13:24:19.449 cacao_playground[46977:5130533] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL file:///Users/young/Desktop/moloco/playground/rust/cacao_playground/target/debug/' *** First throw call stack: ( 0 CoreFoundation 0x00007fff205f81db exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff20331d92 objc_exception_throw + 48 2 CoreFoundation 0x00007fff20621352 +[NSException raise:format:arguments:] + 88 3 Foundation 0x00007fff213e04d2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191 4 UserNotifications 0x00007fff2a4fa540 53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke + 985 5 libdispatch.dylib 0x00007fff202dc806 _dispatch_client_callout + 8 6 libdispatch.dylib 0x00007fff202dd98c _dispatch_once_callout + 20 7 UserNotifications 0x00007fff2a4fa165 +[UNUserNotificationCenter currentNotificationCenter] + 101 8 cacao_playground 0x000000010d540be6 ZN60$LT$$LP$$RP$$u20$as$u20$objc..message..MessageArguments$GT$6invoke17h3fc300ea76f1fcadE + 70 9 cacao_playground 0x000000010d53f282 _ZN4objc7message8platform15send_unverified17he01a71148119e4eaE + 98 10 cacao_playground 0x000000010d54024b _ZN5cacao18user_notifications18NotificationCenter6notify17h59789fbb44092ba5E + 2619 11 cacao_playground 0x000000010d52a77c ZN85$LT$cacao_playground..BasicApp$u20$as$u20$cacao..macos..app..traits..AppDelegate$GT$20did_finish_launching17h9887249749ff2e54E + 108 12 cacao_playground 0x000000010d52b5ce _ZN5cacao5macos3app8delegate20did_finish_launching17h35985f97e2106380E + 46 13 CoreFoundation 0x00007fff20573a53 CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 12 14 CoreFoundation 0x00007fff2060f4d9 _CFXRegistrationPost_block_invoke + 49 15 CoreFoundation 0x00007fff2060f454 _CFXRegistrationPost + 496 16 CoreFoundation 0x00007fff20544cce _CFXNotificationPost + 736 17 Foundation 0x00007fff212b6bb8 -[NSNotificationCenter postNotificationName:object:userInfo:] + 59 18 AppKit 0x00007fff22d8e440 -[NSApplication _postDidFinishNotification] + 305 19 AppKit 0x00007fff22d8e192 -[NSApplication _sendFinishLaunchingNotification] + 208 20 AppKit 0x00007fff22d8b331 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 541 21 AppKit 0x00007fff22d8af87 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665 22 Foundation 0x00007fff212e2306 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308 23 Foundation 0x00007fff212e2176 _NSAppleEventManagerGenericHandler + 80 24 AE 0x00007fff2635e7f3 _AppleEventsCheckInAppWithBlock + 15720 25 AE 0x00007fff2635df0e _AppleEventsCheckInAppWithBlock + 13443 26 AE 0x00007fff26356c23 aeProcessAppleEvent + 448 27 HIToolbox 0x00007fff287d6012 AEProcessAppleEvent + 54 28 AppKit 0x00007fff22d85610 _DPSNextEvent + 2046 29 AppKit 0x00007fff22d83945 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1364 30 AppKit 0x00007fff22d75c69 -[NSApplication run] + 586 31 cacao_playground 0x000000010d540b96 ZN60$LT$$LP$$RP$$u20$as$u20$objc..message..MessageArguments$GT$6invoke17h11fd747e9c6b6bd4E + 70 32 cacao_playground 0x000000010d53eccc _ZN4objc7message8platform15send_unverified17h66e57c952470fa58E + 92 33 cacao_playground 0x000000010d5307c6 _ZN5cacao5macos3app12App$LT$T$GT$3run17h185027ef278d9109E + 1206 34 cacao_playground 0x000000010d52a7cb _ZN16cacao_playground4main17hf4adb535eeac4ec1E + 59 35 cacao_playground 0x000000010d529d4e _ZN4core3ops8function6FnOnce9call_once17hfad80ba2a9fe4a31E + 14 36 cacao_playground 0x000000010d531021 _ZN3std10sys_common9backtrace28rust_begin_short_backtrace17he91fbb5a9ef377b9E + 17 37 cacao_playground 0x000000010d52ab94 _ZN3std2rt10langstart28$u7b$$u7b$closure$u7d$$u7d$17h48ed62f72d20011eE + 20 38 cacao_playground 0x000000010d5d087a _ZN3std2rt19lang_start_internal17h9fcc861d49447111E + 650 39 cacao_playground 0x000000010d52ab5e _ZN3std2rt10lang_start17h96fe9822a85ecbd5E + 46 40 cacao_playground 0x000000010d52a856 main + 22 41 libdyld.dylib 0x00007fff204a1f3d start + 1 ) libc++abi: terminating with uncaught exception of type NSException [1] 46977 abort cargo run

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.