From 4cfdb71ee1f52e0761d61e8e73cb7395a79d65df Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Fri, 16 Oct 2026 00:52:52 -0400
Subject: [PATCH] notification: Use non-deprecated methods for bundle detection
when available
Using the core foundation functions and types is deprecated on macOS 11+.
---
.../cocoa/SDL_cocoanotification.m | 40 +++++++++++++------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/src/notification/cocoa/SDL_cocoanotification.m b/src/notification/cocoa/SDL_cocoanotification.m
index 34f98e47a252d..43502db8b9a10 100644
--- a/src/notification/cocoa/SDL_cocoanotification.m
+++ b/src/notification/cocoa/SDL_cocoanotification.m
@@ -29,7 +29,7 @@
#include "../../events/SDL_notificationevents_c.h"
#include "../../video/SDL_surface_c.h"
-#import <Foundation/Foundation.h>
+#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
#import <UserNotifications/UNNotification.h>
#import <UserNotifications/UNNotificationAction.h>
#import <UserNotifications/UNNotificationAttachment.h>
@@ -91,21 +91,37 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti
static bool ShouldEnableNotifications(void)
{
#if defined(SDL_PLATFORM_MACOS)
- /* Notifications outside of an app bundle are unsupported, and will crash with an
+ /* Notifications outside an app bundle are unsupported, and will crash with an
* unhandled exception error, deep within a system library.
- *
- * FIXME: These functions are deprecated, find a modern way.
*/
- CFBundleRef bundle = CFBundleGetMainBundle();
- CFURLRef bundleUrl = CFBundleCopyBundleURL(bundle);
+ if (@available(macOS 11, *)) {
+ @autoreleasepool {
+ NSBundle *bundle = [NSBundle mainBundle];
+ NSURL *bundleUrl = [bundle bundleURL];
- CFStringRef uti;
- if (CFURLCopyResourcePropertyForKey(bundleUrl, kCFURLTypeIdentifierKey, &uti, NULL) &&
- uti && UTTypeConformsTo(uti, kUTTypeApplicationBundle)) {
- return true;
- }
+ UTType *type = nil;
+ if ([bundleUrl getResourceValue:&type forKey:NSURLContentTypeKey error:nil] &&
+ type && [type conformsToType:UTTypeApplicationBundle]) {
+ return true;
+ }
- return false;
+ return false;
+ }
+ } else {
+ // Deprecated pre-macOS 11 method.
+ CFBundleRef bundle = CFBundleGetMainBundle();
+ CFURLRef bundleUrl = CFBundleCopyBundleURL(bundle);
+ bool ret = false;
+
+ CFStringRef uti = NULL;
+ if (CFURLCopyResourcePropertyForKey(bundleUrl, kCFURLTypeIdentifierKey, &uti, NULL) && uti) {
+ ret = UTTypeConformsTo(uti, kUTTypeApplicationBundle);
+ CFRelease(uti);
+ }
+
+ CFRelease(bundleUrl);
+ return ret;
+ }
#else
// iOS can always enable notificaions.
return true;