Skip to content

refactor: use the new NotificationFramework for pushing notifications#56

Open
nicholaswmin wants to merge 1 commit intovjeantet:masterfrom
nicholaswmin:refactor-notification-framework
Open

refactor: use the new NotificationFramework for pushing notifications#56
nicholaswmin wants to merge 1 commit intovjeantet:masterfrom
nicholaswmin:refactor-notification-framework

Conversation

@nicholaswmin
Copy link
Copy Markdown

Fixes #52

Replace NSUserNotification API with UserNotifications.frameworks API.

  • Import UserNotifications/UserNotifications.h in alerter/AppDelegate.h and alerter/AppDelegate.m.
  • Conform to UNUserNotificationCenterDelegate instead of NSUserNotificationCenterDelegate in alerter/AppDelegate.h.
  • Replace NSUserNotification with UNNotificationRequest for creating notifications in alerter/AppDelegate.m.
  • Replace NSUserNotificationCenter delegate methods with UNUserNotificationCenter delegate methods in alerter/AppDelegate.m.
  • Update methods to use UNUserNotificationCenter for managing notifications in alerter/AppDelegate.m.
  • Remove references to NSUserNotification in alerter/main.m.

Fixes vjeantet#52

Replace `NSUserNotification` API with `UserNotifications.frameworks` API.

* Import `UserNotifications/UserNotifications.h` in `alerter/AppDelegate.h` and `alerter/AppDelegate.m`.
* Conform to `UNUserNotificationCenterDelegate` instead of `NSUserNotificationCenterDelegate` in `alerter/AppDelegate.h`.
* Replace `NSUserNotification` with `UNNotificationRequest` for creating notifications in `alerter/AppDelegate.m`.
* Replace `NSUserNotificationCenter` delegate methods with `UNUserNotificationCenter` delegate methods in `alerter/AppDelegate.m`.
* Update methods to use `UNUserNotificationCenter` for managing notifications in `alerter/AppDelegate.m`.
* Remove references to `NSUserNotification` in `alerter/main.m`.
@Tobbe
Copy link
Copy Markdown

Tobbe commented Mar 14, 2025

What's the status of this PR? Is it ready to be merged? If I pull this down, can I build it and use it with the new MacOS notification API? What about code signing? Is that something I need to read up on? I've never have to deal with that before.

@nicholaswmin
Copy link
Copy Markdown
Author

@Tobbe Hi Tobbe; sorry for the late reply - should be good. No code-signing.
But should be buildable, have you tried doing so?

@Tobbe
Copy link
Copy Markdown

Tobbe commented Mar 18, 2025

No worries at all about the reply. Thanks for getting back to me 🙏
I haven't tried building yet, but next time I have time for the side-project I need this for I'll give it a go.
About code signing – it was more about being able/allowed to show the alerts. Maybe it was specifically for having a custom icon? But don't worry about it. I'll just try it and see what happens :D

@quarkw
Copy link
Copy Markdown

quarkw commented May 1, 2025

@nicholaswmin this doesn't seem to build for me:

Macos Sequoia 15.4.1 (24E263)
Xcode Version 16.3 (16E140)
       > /private/tmp/nix-build-alerter-1.0.1.drv-0/source/alerter/AppDelegate.m:414:5: error: statement requires expression of integer type ('NSString *' invalid)
       >   414 |     switch (notification.request.content.categoryIdentifier) {
       >       |     ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       > /private/tmp/nix-build-alerter-1.0.1.drv-0/source/alerter/AppDelegate.m:415:14: error: integer constant expression must have integer type, not 'NSString *'
       >   415 |         case @"actionsCategory": {
       >       |              ^~~~~~~~~~~~~~~~~~
       > /private/tmp/nix-build-alerter-1.0.1.drv-0/source/alerter/AppDelegate.m:423:14: error: integer constant expression must have integer type, not 'NSString *'
       >   423 |         case @"replyCategory": {
       >       |              ^~~~~~~~~~~~~~~~
       > /private/tmp/nix-build-alerter-1.0.1.drv-0/source/alerter/AppDelegate.m:429:14: error: integer constant expression must have integer type, not 'NSString *'
       >   429 |         case @"closeCategory": {
       >       |              ^~~~~~~~~~~~~~~~
       > 4 errors generated.

@vjeantet
Copy link
Copy Markdown
Owner

Hello, I've been investigating the use of this new API over the past few months.

The biggest issue is the loss of features (sender, ignoresDoNotDisturb, dynamic buttons, dynamic image...) and the need to restructure the app as a .app bundle rather than a simple CLI executable to make the new framework work.

😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use the new Apple Notification Framework

4 participants